即使在设置launchMode ="singleTop"后仍在重新创建活动

Abd*_*tir 3 android android-manifest android-intent android-fragments android-activity

我使用自定义方案为Fitbit实现OAuth,为此我需要Activity在用户登录默认浏览器后从堆栈顶部使用调用实例,并重定向到CALLBACK URL.而不是onNewIntent()被称为,Activity只是重新创建,这不是我需要的.

<activity
        android:name=".AppsAndDevicesActivity"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="snbr" />
        </intent-filter>
    </activity>  
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码从Fragment打开浏览器:

String url = Fitbit.buildAuthenticationURL();
Log.d("URL", url);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
this.getActivity().startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)

san*_*Xme 6

使用launchmode作为singleTask,因为:

singleTask:

系统创建新任务并在新任务的根目录下实例化活动.但是,如果活动的实例已存在于单独的任务中,则系统会通过调用其onNewIntent()方法将意图路由到现有实例,而不是创建新实例.一次只能存在一个活动实例.

注意:虽然活动在新任务中启动,但"后退"按钮仍会将用户返回到上一个活动.