Compilation error using PendingIntent

别来无恙 提交于 2019-12-13 06:47:47

问题


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);


来源:https://stackoverflow.com/questions/11530830/compilation-error-using-pendingintent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!