Xur*_*ajB 20 android android-activity
我的应用程序上有一个带图标的常用菜单.单击图标将启动活动.有没有办法知道一个活动是否已经在运行并阻止它多次启动(或从多个条目开始)?我也可以将处于onPause状态的活动带到前面吗?
Adi*_*mro 39
用这个:
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Run Code Online (Sandbox Code Playgroud)
一边开始Activity.
来自文件:
如果在传递给Context.startActivity()的Intent中设置,则此标志将导致已启动的活动在其任务的历史堆栈中已经运行时被带到其前面.
我通过执行以下操作使其完美运行。在调用方活动或服务中(甚至来自另一个应用程序)
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(APP_PACKAGE_NAME);
//the previous line can be replaced by the normal Intent that has the activity name Intent launchIntent = new Intent(ActivityA.this, ActivityB.class);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(launchIntent);
Run Code Online (Sandbox Code Playgroud)
并在接收器活动的清单中(我想防止打开两次)
<activity android:name=".MainActivity"
android:launchMode="singleTask"
>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16358 次 |
| 最近记录: |