Compilation error using PendingIntent

2019-09-15 02:16发布

问题:

So I'm working on a chunk of code that will allow me to run an app out of the Status bar at the top I'm a good way into it and almost finished. I just need a second opinion on why my "PendingIntent.getActivity(this,that,next,thing);" Its not compiling. Here's the code

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;

public class NotifyMe extends Activity {
NotificationManager nm;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Intent MainActivity = new Intent(this, MainActivity.class);
    PendingIntent pi = new PendingIntent.getActivity(this, 0, intent, 0);
    String body = "Simple message";
    String title = "Hello World";
    Notification n = new Notification(R.drawable.note, body, System.currentTimeMillis());
    n.setLatestEventInfo(this, title, body, pi);

}
}

So I might be doing this all wrong, any tips in this matter will be greatly appreciated.

回答1:

 PendingIntent pi = new PendingIntent.getActivity(this, 0, intent, 0);

Dont need new.

More importantly, you need to focus on getting your eclipse environment setup so that you can at least view the error messages. They should occur in an area called Problems, and when you report an error on StackOverflow you can include what the error message is. Let us know if you have questions about your environment.



回答2:

PendingIntent pi = PendingIntent.getActivity(FancyDiamondResultActivity.this, 0, intent, 0);