2

我有以下代码可以打开浏览器访问我的社交资料:

    ImageView iv1 = (ImageView) dialog.findViewById(R.id.imgFB);
    iv1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Uri uri = Uri.parse("https://www.facebook.com/profile");                
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);  
            }
    });

现在,当我选择浏览器打开配置文件并按back时,它不仅会关闭浏览器,还会关闭我的应用程序。有什么方法可以在让我的应用程序在后台运行的同时关闭浏览器?

更新

这工作正常:

ImageView iv1 = (ImageView) dialog.findViewById(R.id.imgFB);
iv1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Uri uri = Uri.parse("https://www.facebook.com/PagesByZ"); //Uri.parse("market://details?id=" + facebookpackagename); 
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        dialog.dismiss();
        startActivity(intent);  
    }
});

现在我没有收到错误,但是当Complete action using窗口出现时,我没有选择一个选项,而是按返回,我的应用程序就关闭了。知道如何解决它,所以如果我按返回它会返回到我的应用程序而不是主页?

更新:以下是重新措辞,以帮助更好地理解问题。

在我的应用程序中,我有一个打开浏览器的图像链接,但如果用户安装了多个浏览器,它会显示“使用完成操作”窗口,我可以在其中选择。如果我按下后退按钮,它应该关闭它回到我的应用程序。相反,如果我按下后退按钮,我的应用程序就会关闭并返回主屏幕

在此处输入图像描述

我的主要活动:http: //pastebin.com/FVwEKLAT

我的安卓清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sikni8.tollculator"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.sikni8.tollculator.MainActivity"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.sikni8.tollculator.CurrentTrip"
            android:label="@string/title_activity_current_trip"
            android:parentActivityName="com.sikni8.tollculator.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.sikni8.tollculator.MainActivity" />
        </activity>
        <activity
            android:name="com.sikni8.tollculator.DisplayTrip"
            android:label="@string/title_activity_display_trip"
            android:parentActivityName="com.sikni8.tollculator" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.sikni8.tollculator" />
        </activity>
        <activity
            android:name="com.sikni8.tollculator.ShowHelp"
            android:label="@string/app_name" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.sikni8.tollculator.MainActivity" />
        </activity>
        <activity
            android:name="com.sikni8.tollculator.ShowSettingOptions"
            android:label="@string/app_name" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.sikni8.tollculator.MainActivity" />
        </activity>
    </application>

</manifest>

我如何确保如果用户改变主意不去浏览器并按下后退按钮,它只是回到我的应用程序而不是进入主屏幕?

如果他们确实转到浏览器并按下将关闭浏览器并且我的应用程序将返回查看的后退,也将修复上述修复?

4

2 回答 2

2

也许一个对话框正试图从一个也关闭的活动(你的 MainActivity)中显示......你是否在他们点击 ImageView 后触发了一个对话框?

也可以看看这个帖子。(因为您的日志显示“com.myapp.tollculator.MainActivity 已泄漏窗口”)

于 2013-08-15T21:25:42.760 回答
1

一些可能的原因/解决方案:

  1. 我不敢相信这是原因,但是您的应用程序是否可能因为您的应用程序或网络浏览器应用程序使用太多内存而被关闭,或者您在低端设备上进行测试?

  2. 另外,请尝试以下标志的组合: FLAG_ACTIVITY_NEW_TASK 、 FLAG_ACTIVITY_NO_HISTORY 、 FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET 。也请尝试

  3. 请检查另一台设备上发生的情况。甚至模拟器。

  4. 请在打开对话框并按返回时显示一些日志。

  5. 请转到设备的设置,看看是否打开了选项(在开发部分)“不保留活动”。

  6. 请仅使用您使用的对话框创建一个全新的项目,然后尝试一下。也许这是一个超出你想象的问题......

  7. 显示您正在使用的活动的清单部分。

  8. 确定代码中的任何地方都没有调用“finish()”吗?

于 2013-08-15T21:54:55.297 回答