0

如何在此处实现从通知中停止重新打开应用程序的代码是我的代码。当我的应用程序最小化时,它会重新打开最后一个活动

扩展广播接收器类

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

  }


}
4

2 回答 2

0

可能的方式:

on 扩展广播接收器类

意图 newIntent = new Intent(con, NotificationAlertForStopper.class);

反对。启动服务(新意图);

然后

公共类 NotificationAlertForStopper 扩展服务

于 2013-10-25T22:15:34.420 回答
0

Intent notifyIntent = new Intent(this,Meditation.class);发生这种情况是因为您已在活动的 onCreate() 中编写了此内容。

基本流程应该是一旦通知出现在您设备的通知托盘中,点击它应该会打开您的活动。

于 2013-10-21T11:57:31.983 回答