如何在此处实现从通知中停止重新打开应用程序的代码是我的代码。当我的应用程序最小化时,它会重新打开最后一个活动
扩展广播接收器类
Intent newIntent = new Intent(con, NotificationAlertForStopper.class); newIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); con.startActivity(newIntent);
NotificationAlertForStopper.java
public class NotificationAlertForStopper extends Activity { private NotificationManager mNotificationManager; private int SIMPLE_NOTFICATION_ID; String getTime="0",aaa; CharSequence contentTitle, contentText; MediaPlayer mediaPlayer,mediaPlayer1; MyDataBase mdb; ArrayList<MoodsTimings> values; String dy; private final int SPLASH_DISPLAY_LENGHT = 15000; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); final Notification notifyDetails = new Notification(R.drawable.appicon,"xxxxxxx",System.currentTimeMillis()); int resID1=getResources().getIdentifier("relax", "raw", getPackageName()); mediaPlayer=MediaPlayer.create(NotificationAlertForStopper.this,resID1); mediaPlayer.start(); mediaPlayer.setLooping(true); int resID2=getResources().getIdentifier("inhale", "raw", getPackageName()); mediaPlayer1=MediaPlayer.create(NotificationAlertForStopper.this,resID2); mediaPlayer1.start(); mediaPlayer1.setLooping(true); new Handler().postDelayed(new Runnable() { @Override public void run() { mediaPlayer.stop(); mediaPlayer1.stop(); mNotificationManager.cancel(SIMPLE_NOTFICATION_ID); } }, SPLASH_DISPLAY_LENGHT); /* try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) {}*/ Context context = getApplicationContext(); contentTitle = "xxxxx"; contentText = "xxxxxxxxxxxx Breathe"; Intent notifyIntent = new Intent(this,Meditation.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(NotificationAlertForStopper.this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent); mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); //mNotificationManager.cancel(SIMPLE_NOTFICATION_ID); finish(); } }