Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resume my application in the same way it resumed from history

I am writing an SDK to be used in hosting app. My SDK creates a notification that needs to resume the app, just the same way as you press on the tasks button and select the app, or long press on Home button and select your app.

Here is what I been trying to do:

        PackageManager packageManager = context.getPackageManager();
        intent = packageManager.getLaunchIntentForPackage(context.getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 10, intent, flags);
        Notification notification = new NotificationCompat.Builder(context).
            setContentIntent(pendingIntent).
            ...
            build();

        getNotificationManager().notify(NOTIFICATION_ID, notification);

I been testing this on host app with one launcher activity with lunching mode "default"(no launching mode been set in the manifest) and my sdk also got 1 activity with lunch mode "singleTask".

  1. So I lunch the app
  2. Start my SDK activity it fires a test notification in onCreat method.
  3. I press home
  4. I click on the notification.

After doing those steps I expect to be returned to my activity but instead it opens another instance of the host launcher activity. What am I missing? How do I make this work?

like image 635
Ilya Gazman Avatar asked Sep 24 '15 08:09

Ilya Gazman


1 Answers

If you wanna resume from where you pause, then remove flag "NEW_TASK". It will not make new task. Hope you find it helpful in your task.

like image 58
Dharvik shah Avatar answered Nov 19 '22 05:11

Dharvik shah