活动开放两次

时间:2018-05-02 07:19:56

标签: android android-activity stack

在我的申请中有3页是

1溅

2登录

3-OTPpage

在启动页面中,相同的值使用putextra方法发送到登录页面 但登录页面打开两次,所以当System.exit(0)登录页面的添加后退按钮将再次打开时, 所以我在清单中添加android:launchMode="singleTask",添加此行转移值后不定期地改变我应该做什么..是否有任何其他方法来防止重复创建活动

活动开始代码

@Override
protected void onResume() {
    super.onResume();
    // The first time mTimeBeforeDelay will be 0.
    long gapTime = System.currentTimeMillis() - mTimeBeforeDelay;
    if (gapTime > SPLASH_SCREEN_MS) {
        gapTime = SPLASH_SCREEN_MS;
    }
    mSplashHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (sharedPreferences.getBoolean("first_time", true)) {
                if (isConnectingToInternet()) {
                    frstrequest();
                } else {
                    ViewDialog1 alert = new ViewDialog1();
                    alert.showDialog(Splash.this, "Make Sure Internet is Connected", R.drawable.no_internet);
                }


            } else {

                Intent i = new Intent(getApplicationContext(), ApplockActivity.class);
                startActivity(i);
                overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
                Splash.this.finish();


            }
        }
    }, gapTime);
    // Save the time before the delay.
    mTimeBeforeDelay = System.currentTimeMillis();
}

@Override
protected void onPause() {
    super.onPause();
    mSplashHandler.removeCallbacksAndMessages(null);
}

清单

  <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Splash"


            android:screenOrientation="portrait">



        </activity>
        <activity
            android:name=".LoginActivity"
           android:noHistory="true"
            android:screenOrientation="portrait">
        </activity>
        <activity

1 个答案:

答案 0 :(得分:2)

如果您的活动是从任何地方拨打两次,那么它会创建两个实例,结果您的活动会打开两次,您可以通过启动模式停止它,请访问this post