开发者

Android notification click, run the main intent?

开发者 https://www.devze.com 2023-01-20 11:22 出处:网络
Hy! public static void addNotification(String sAppname, String sDescription) { NotificationManager notifManager = (NotificationManager) mycontext.getSystemService(NOTIFICATION_SERVICE);

Hy!

    public static void addNotification(String sAppname, String sDescription) {

     NotificationManager notifManager = (NotificationManager) mycontext.getSystemService(NOTIFICATION_SERVICE);  
     Notification note = new Notification(R.drawable.icon, sDescription, System.currentTimeMillis());  

     Intent i = new Intent (mycontext, mStart.class)
             .setAction(Intent.ACTION_MAIN)
             .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

   开发者_运维知识库  PendingIntent contentIntent = PendingIntent.getActivity(mycontext, 0, i, 0); 

     note.setLatestEventInfo(mycontext, sAppname, sDescription, contentIntent);  

     notifManager.notify(NOTIFY_ID, note);  

}

mStart is my first activity

if i click on the notification this code is "re-create" the intent, and show up a new one.

i dont want this. i d like to show up the existing main intent. how to?


The solution is:

in manifest file add the following: singleTask="true"

0

精彩评论

暂无评论...
验证码 换一张
取 消