To solve this problem you can rely on Android Tasks.
What you have to do:
Launch WebView Activities using flags: Intent.FLAG_ACTIVITY_NEW_TASK
and Intent.FLAG_ACTIVITY_MULTIPLE_TASK
Inside these activities call getTaskId()
and make the ID available to your main activity. When you want to resume an activity, do the following:
ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
am.moveTaskToFront(taskId, 0);
Requires permission permission android.Manifest.permission.REORDER_TASKS
When you want to return to your main task from a WebView task (which consists of a single Activity), do this:
Context context = getApplicationContext();
String packageName = context.getPackageName();
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(launchIntent);