为什么我的活动重新创建而不是重新开始

时间:2016-07-28 10:38:47

标签: android

我以此开始我的活动

 Intent window = new Intent(mContext, popup.class);
 window.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_MULTIPLE_TASK);  
 mContext.startActivity(window);

我的活动已开始,日志

 onCreate
 onStart
 onResume

现在我想停止我的活动我使用这个

 moveTaskToBack(true); //i don't know if this best way to stop an activity

和日志

onPause
onStoped
  

onDestroy未调用

现在我想重新启动我使用的相同活动

   Intent window = new Intent(mContext, popup.class);
   window.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_MULTIPLE_TASK);  
   mContext.startActivity(window);

这里没有重新启动它创建新活动的活动

 onCreate
 onStart
 onResume

这是我在清单

中的活动
<activity
        android:name=".activity.popup"
        android:taskAffinity=".MyDialog"
        android:configChanges="orientation|screenSize"
        android:exported="true"
        android:label="@string/app_name"
        android:theme="@style/Theme.FloatingWindow.Popup"
        android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
        tools:ignore="ExportedActivity"

        >

  </activity>

注意**如果我使用launchMode singleInstance重新启动而不创建新活动但是这里有问题我不能为不同的数据设置相同的活动

1 个答案:

答案 0 :(得分:0)

不要添加此标记Intent.FLAG_ACTIVITY_NEW_TASK,并将此标记添加到清单android:launchMode="singleInstance"中的活动

相关问题