赞
踩
1. 通过不同的入口启动应用,会重复调用Ability的onStart方法,也就是不同的Intent会创建多个Ability的实例。
方法一: 在config.json中设置为单例模式
- {
- "orientation": "unspecified",
- "visible": true,
- "name": "com.example.myapplication.SplashScreenAbility",
- "icon": "$media:icon",
- "description": "$string:splashscreenability_description",
- "label": "$string:entry_MainAbility",
- "type": "page",
- "launchType": "singleMission"
- 或者
- "launchType": "singleton"
- }
方法二:
- // FLAG_ACTIVITY_BROUGHT_TO_FRONT 常量值为 4194304
- public void onStart(Intent intent) {
- if (intent.getFlags() & FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) {
- terminateAbility();
- return;
- }
- // 继续后续处理逻辑
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。