如何实现停止重新打开应用程序的代码 这里的通知是我的代码。 当myapplication最小化时,它会重新打开最后一个活动
扩展广播接收器类
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(); } }
答案 0 :(得分:0)
这是因为您在活动的onCreate()中写了Intent notifyIntent = new Intent(this,Meditation.class);
。
基本流程应该是在您的设备的通知托盘中显示通知后,点击它会打开您的活动。
答案 1 :(得分:0)
on扩展广播接收器类
Intent newIntent = new Intent(con,NotificationAlertForStopper.class);
CON的 startService 强>(newIntent);
然后
公共类NotificationAlertForStopper扩展服务