문제

In my Android app I have a list of opened instances of the same activity (This activity basically contains a WebView.) When the user clicks on an item in the list, I want to resume the according activity showing the correct website. However, using an intent with flag Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT will not do the trick since the Activity is the same (just different instances with different extras).

I think I have to use multiple (e.g., 10) identical Activities with different names. Each website is then launched in its own Activity. However, when I want to open more than 10 websites, I run into troubles again.

Any other ideas how to solve this issue?

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top