Bringing activity back from foreground

I stuck in a problem. Suppose there is an activity A now, user press Home key, and put A into background. now, after remaining in background for a while, it will generate a notification. On clicking on that notification, it will bring back the exact same activity which was in the background. Like, after pressing home key, if user start the application again by clicking on the icon or from the recent launched history, then android re-opens exactly last activity in it's previous state. Here, I dont want to detect which was the last activity. My activity is fixed, I just want to bring it back at its previous state on clicking on the notification ? Is that possible ? how to do that ? here is my code for notification,

    private void generateNotification(Context context, String message, String data) {   
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.notification, message,  System.currentTimeMillis());

    Intent notificationIntent = new Intent(context, MenuActivity.class);        
    //notificationIntent.setFlags(Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);

    Bundle bundle = new Bundle();
    bundle.putString("data",data);
    notificationIntent.putExtras(bundle);

    //Constants.NOTIFICATION_ID++;
    notification.setLatestEventInfo(context, context.getString(R.string.app_name), message, PendingIntent.getActivity(context, 0, notificationIntent, Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR));
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(Constants.NOTIFICATION_ID, notification);            
}

使用Intent.FLAG_ACTIVITY_CLEAR_TOP代替FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY

链接地址: http://www.djcxy.com/p/26172.html

上一篇: 处理应用程序未打开时的主页按钮事件

下一篇: 从前台引回活动