0

I have a notifications in my app with Pending intent set. When I use my application i move in several activities. Login -> Main Screen -> About etc. I want to restore my application to foregrownd but I don't know which is the current activity to set it class in Intent constructor. I want to restore it from the notifications. to be a way to back to app if opened and opened again if closed,because notifications comes from Service.

I want to bring back the activity which is was on top when user bring it to back. in other words i want to simulate the behaviour -> back to home screen of device [ in this time app is run but is in background] and if click on app icon .. the application restores last activity/ bring it to front where i am when click home button but to do this also from notification

Is there a way to do this?

Thanks

user1106234
  • 223
  • 4
  • 15
  • Look at http://stackoverflow.com/questions/6575730/notification-to-restore-a-task-rather-than-a-specific-activity this is exactly what you want – David Wasser Mar 21 '13 at 19:52

1 Answers1

0
            NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notification = new Notification(R.drawable.icon,"Details", System.currentTimeMillis());
            RemoteViews remoteView = new RemoteViews(getPackageName(),R.layout.custom_notification);
            remoteView.setImageViewResource(R.id.icon, R.drawable.icon);
            remoteView.setTextViewText(R.id.Mesg, "Status : "+ details);
            notification.contentView = remoteView;
            Intent notificationIntent = new Intent(context,Form.class).putExtra("layout", "99");
            PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,Notification.FLAG_AUTO_CANCEL);
            notification.contentIntent = contentIntent;
            notification.flags = Notification.FLAG_AUTO_CANCEL+ Notification.FLAG_ONLY_ALERT_ONCE;
            manager.notify(45, notification);

and in my on create of my application ia m using

 Intent i = getIntent();
    k = Integer.parseInt(i.getStringExtra("layout"));
    Log.i(TAG, ">>>>>>>>>>" + k);
    if (k == 99) {
        finish();
    }

This will check if your activity still exist or not.. If the acticity is killed or closed it will take you the activity on the top of the stack . If the application is completely closed it will not do anything

MRX
  • 1,400
  • 3
  • 12
  • 32
  • But if top activity is some of other activities not start up ? – user1106234 Feb 15 '13 at 07:07
  • I want to bring back the activity which is was on top when user bring it to back. in other words i want to simulate the behaviour -> back to home screen of device [ in this time app is run but is in background] and if click on app icon .. the application restores last activity/ bring it to front where i am when click home button but to do this also from notification – user1106234 Feb 15 '13 at 07:11
  • ya I think this will do the same I am doin the similar thing is my application. my flow is as follows Login->home page->FormPage. Now if I press the Home button on device and click on the notification symbol it will tke me to form page. Even if from form page i navigate back which brings home page on top of stack and click on home button of device and repeat the same it will take me to the home page of my application..let me check if I missed something for more reference ... – MRX Feb 15 '13 at 07:42