如果有一个应用程序有登录活动,并且它通过单击图标启动。此登录活动也可以由另一个意图启动。问题是当活动运行时(通过触摸应用程序图标启动),当它收到不同的意图调用时,它会启动另一个登录活动。
当收到不同的意图调用来启动登录活动时,如何在关闭当前正在运行的活动后再次启动登录活动。
上面提到的不同意图是,当用户选择具有特定扩展名的特定文件时,我的应用程序必须启动。
<activity
android:name=".login.Login"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="content"
android:mimeType="application/octet-stream"
android:pathPattern=".*\\.chat"
tools:ignore="AppLinkUrlError" />
</intent-filter>
</activity>
第二个意图称为 ,我的应用程序下载所选文件并将其存储在内部存储中。
这是登录活动中的 onCreate 方法
public void onCreate(Bundle savedInstanceState) {
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onCreate(savedInstanceState);
if (isTaskRoot()) {
Uri data = getIntent().getData();
if (data != null) {
getIntent().setData(null);
try {
importData(data);
} catch (Exception e) {
// warn user about bad data here
finish();
return;
}
}
}
...................................
}
当用户选择指定文件时,应用程序会启动另一个活动。那么堆栈中有两个登录活动。帮我摆脱这个
尝试了单实例、单任务解决方案。但是当启动模式设置为 singleinstance 或 singletask 并且收到第二个意图调用时,它不会调用
导入数据()
方法。所以我想下载的文件没有下载..
这里我使用“singleTask”作为launchMode。然后当再次调用 Activity 时我必须使用 onNewIntent() 。下面的链接给出了更多解释。
“onCreate()”方法未被另一个意图过滤器调用 https://stackoverflow.com/questions/53588183/oncreate-method-is-not-called-from-another-intent-filter
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)