android - 在堆栈中生成同一应用程序的多个实例

标签 android app-launcher

如果有一个应用程序有一个登录 Activity ,它通过图标点击启动。此登录 Activity 也可以由另一个 Intent 启动。问题是当 Activity 正在运行时(通过触摸应用程序图标启动)并且当它收到不同的 Intent 调用时它会启动另一个登录 Activity 。

当收到不同的 Intent 调用以启动登录 Activity 时,如何在关闭当前正在运行的 Activity 后再次启动登录 Activity 。 上面提到的不同 Intent 是,当用户选择具有特定扩展名的特定文件时,必须启动我的应用程序。

<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>

第二个 Intent 被调用,我的应用程序下载选定的文件并将其存储在内部存储器中。 这是登录 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;
            }
        }
    }

 ...................................

}

当用户选择指定的文件时,应用会启动另一个 Activity 。然后堆栈中有两个登录 Activity 。帮我摆脱这个

尝试了单实例、单任务解决方案。但是当启动模式设置为单实例或单任务并且收到第二个 Intent 调用时,它不会调用

importData()

方法。所以我要下载的文件没有下载..

最佳答案

这里我使用“singleTask”作为启动模式。然后,当再次调用 Activity 时,我必须使用 onNewIntent() 。下面的链接给出了更多解释。

“onCreate()” method is not called from another intent filter

关于android - 在堆栈中生成同一应用程序的多个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53552228/

相关文章:

javascript - 在 Android 上使用 JQM 和 PhoneGap 闪烁/闪烁

android - 如何在 honeycomb/ics 上打开应用程序小部件选择器?

macos - 快银死了吗?

java - 在 libgdx 中截图

java - Firebase数据库如何从1个引用中获取一些值并等于2个引用来获取其键和值

java - Eclipse 中的 Android 开发无法访问代码 Intent

eclipse - 由于巨大的类路径,GWT 启动器出现错误

c# - GsmCommMain - C# 中没有电话连接错误(使用宽带棒发送短信)

iphone - GEO 提醒启动应用程序

python - 如何使用 Kupfer (python) 修复 TypeError : glib. spawn_async?