关于通知意图,我遇到了一些问题。我有2项活动(A& B)。活动A是我的应用程序的主要活动。用户将经历的第一个活动。至于活动B是指用户通过点击活动A上的按钮进入。
事情是,当我点击我的通知时,它会将我引导至活动B.然后将我引回活动A onBackPressed。但是当我关闭应用程序并通过多任务选项将其打开时,它会在活动B中恢复我的应用程序。我希望应用程序在关闭它之后重新启动活动A.
订单应该是
活动A - >活动B.
通知 onClick - >活动B( onBackPressed ) - >活动A - >关闭。
使用多任务功能重新打开应用程序/打开 - >活动A
如果我能提供任何其他信息以便正确理解我的问题,请告诉我。
GCM_Intent.class
Notification note = new Notification(icon, msgTopic ,System.currentTimeMillis());
Intent i=new Intent(this, Activity_B.class);
i.putExtra("topicId", topicId);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi=PendingIntent.getActivity(this, CommunitiesappConstant.NOTIFICATION_ID, i, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
note.setLatestEventInfo(this, topicName ,msgInfo+message, pi);
note.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
note.ledARGB |= 0xff0000ff;
note.ledOffMS |= 1000;
note.ledOnMS |= 300;
mgr.notify(CommunitiesappConstant.NOTIFICATION_ID, note);
活动B.class
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
Bundle bundle = getIntent().getExtras();
topicId = bundle.getString("topicId");
}
@Override
public void onBackPressed() {
super.onBackPressed();
Log.e(TAG, "onBackPressed");
Intent i = new Intent(Activity_B.this, Activity_A.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
答案 0 :(得分:1)
通知是您可以在应用程序的正常UI之外向用户显示的消息。这是使用通知的完美代码。
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
答案 1 :(得分:0)
这样做onback press(),
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
current.finish()