Android 打开文件时防止应用程序/活动的多个实例
我有一项活动是我申请的基础。问题就在这里Android 打开文件时防止应用程序/活动的多个实例,android,android-lifecycle,Android,Android Lifecycle,我有一项活动是我申请的基础。问题就在这里 我创建了一个名为Instance1的活动实例 然后导航回主菜单,将我的活动发送到后台onPause和onStop 然后我导航到Gmail,打开电子邮件附件 这将创建我的活动“Instance2”的新实例(我知道这一点,因为我记录了实例是什么)。我现在在活动中所做的任何事情都在这个新实例中 如果我随后导航到gmail,onDestroy在Instance2上被调用,然后如果我通过触摸图标打开我的应用程序,原始的Instance1onRestart被调用
- 我创建了一个名为
的活动实例Instance1
- 然后导航回主菜单,将我的活动发送到后台<在
上调用code>onPause和Instance1
onStop
- 然后我导航到
,打开电子邮件附件Gmail
- 这将创建我的活动“Instance2”的新实例(我知道这一点,因为我记录了实例是什么)。我现在在活动中所做的任何事情都在这个新实例中
- 如果我随后导航到gmail,
在onDestroy
上被调用,然后如果我通过触摸图标打开我的应用程序,原始的Instance2
Instance1
被调用onRestart
manifest.xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.dog" />
</intent-filter>
问题
为什么它不能意识到有一个实例正在运行并打开它
添加
我使用singleInstance并将其移动到我的活动标记中。但是,现在我无法获取电子邮件附件数据?之前我使用了以下方法
Intent intent = getIntent();
if (intent != null) {
Log.d("MainActivity","Intent not null");
Uri u = intent.getData();
if (u != null) {
Log.d("MainActivity","URI not null");
launchMode标记是元素的一部分,而不是应用程序元素
您应该使用singleTop重新使用现有活动 您尝试过单实例吗?您尝试过android:launchMode=“singleInstance”?确定
singleInstance
没有工作singleTop
。现在的问题是,当我转到getIntent.getData()时,onRestart方法中没有接收到附件数据代码>?是否调用了onNewIntent
?是否调用了它,并且意图是否得到了数据。然而,现在在阅读gmail的时候出现了权限问题。我已经添加了这些权限,但仍然没有乐趣。我讨厌安卓。你帮我解决了我原来的问题,还有更多。谢谢,太好了。Android生命周期可能有点令人沮丧,但听起来你就快到了,所以不要放弃!如果你不了解权限的话,试着问一个新问题。
Intent intent = getIntent();
if (intent != null) {
Log.d("MainActivity","Intent not null");
Uri u = intent.getData();
if (u != null) {
Log.d("MainActivity","URI not null");