2017-10-27 1 views
-1

私のアプリケーションにはいくつかのアクティビティがあります。最初に、(startActivityWithResult)(startActivityWithResult)を作成して、そのユーザーからのダイアログアクティビティ「First run wizard」(B)を実行して、いくつかの設定アクティビティ(C)を起動できるアクティビティ(A)を起動します。アクティビティBを元に戻す代わりに(元のアクティビティBを元に戻す)代わりに、アクティビティBから戻ってアクティビティCから戻るとき(または元のアクティビティBの新しいインスタンスを作成するとき) saveInstanceState。ユーザーはその新しいインスタンスのみを表示しますが、古いインスタンスはまだ存在し、メモリを消費してonStartとonStopを取得します(非表示の場合でも)。今私はBの複数のインスタンスを持っていて、新しいインスタンスが作成されています.Aに戻る前にBのインスタンスをすべて閉じる必要があります。 私の質問は、同じインスタンスBのインスタンスを複数作成しないようにする方法ですか?私が設定しようとするsingleTopsingleTaskまたはsingleInstanceマニフェストのBのためには動作しませんでした。子アクティビティの終了後にアクティビティの新しいインスタンスを作成しないようにする

活動:活動Cを得るための別の方法は自分のアプリケーションでありますので、私は活動のBまたはC

を作成しながら、現在、私は、マニフェストファイルがあります任意のフラグを設定していない活動C.を変更したくありません:

<activity 
    android:name=".A" 
    android:label="@string/app_name" 
    android:launchMode="singleTop" 
    android:screenOrientation="portrait" 
    android:stateNotNeeded="true"> 
    <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
    </intent-filter> 
</activity> 

アクティビティB:

<activity 
    android:name=".B" 
    android:launchMode="singleInstance" 
    android:label="B" 
    android:parentActivityName=".A" 
    android:theme="@style/WizardDialog"> 
</activity> 

アクティビティC:

<activity 
    android:name=".C" 
    android:label="C"> 
</activity> 

はBのために(Bの下での活動A部分的に見える)WizardDialogテーマをあります

<style name="WizardDialog" parent="@style/AppDialogBasic"> 
    <item name="android:maxWidth">300dp</item> 
    <item name="android:maxHeight">360dp</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowSoftInputMode">stateAlwaysHidden</item> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:windowActionModeOverlay">true</item> 
    </style> 

また、活動の出力があるがsysdump:

ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities) 
Display #0 (activities from top to bottom): 
    Stack #1: 
    mFullscreen=true 
    mBounds=null 
    Task id #88 
    mFullscreen=true 
    mBounds=null 
    mMinWidth=-1 
    mMinHeight=-1 
    mLastNonFullscreenBounds=null 
     TaskRecord{be4d271 #88 A=com.a.a U=0 StackId=1 sz=3} 
     Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.a.a/.WaitingActivity } 
     Hist #2: ActivityRecord{fd61815 u0 com.a.a/.SetupWizardActivity t88} 
      Intent { cmp=com.a.a/.SetupWizardActivity } 
     ProcessRecord{d21940e 17900:com.a.a/u0a79} 
     Hist #1: ActivityRecord{f891058 u0 com.a.a/.SetupWizardActivity t88} 
      Intent { cmp=com.a.a/.SetupWizardActivity } 
     ProcessRecord{d21940e 17900:com.a.a/u0a79} 
     Hist #0: ActivityRecord{e2bb06a u0 com.a.a/.WaitingActivity t88} 
      Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.a.a/.WaitingActivity } 
      ProcessRecord{d21940e 17900:com.a.a/u0a79} 

    Running activities (most recent first): 
     TaskRecord{be4d271 #88 A=com.a.a U=0 StackId=1 sz=3} 
     Run #2: ActivityRecord{fd61815 u0 com.a.a/.SetupWizardActivity t88} 
     Run #1: ActivityRecord{f891058 u0 com.a.a/.SetupWizardActivity t88} 
     Run #0: ActivityRecord{e2bb06a u0 com.a.a/.WaitingActivity t88} 

    mResumedActivity: ActivityRecord{fd61815 u0 com.a.a/.SetupWizardActivity t88} 

    Stack #0: 
    mFullscreen=true 
    mBounds=null 
    Task id #75 
    mFullscreen=true 
    mBounds=null 
    mMinWidth=-1 
    mMinHeight=-1 
    mLastNonFullscreenBounds=null 
     TaskRecord{cf23856 #75 I=com.google.android.apps.nexuslauncher/.NexusLauncherActivity U=0 StackId=0 sz=1} 
     Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000100 cmp=com.google.android.apps.nexuslauncher/.NexusLauncherActivity } 
     Hist #0: ActivityRecord{de71b57 u0 com.google.android.apps.nexuslauncher/.NexusLauncherActivity t75} 
      Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000100 cmp=com.google.android.apps.nexuslauncher/.NexusLauncherActivity } 
      ProcessRecord{bc76608 2088:com.google.android.apps.nexuslauncher/u0a20} 

    Running activities (most recent first): 
     TaskRecord{cf23856 #75 I=com.google.android.apps.nexuslauncher/.NexusLauncherActivity U=0 StackId=0 sz=1} 
     Run #0: ActivityRecord{de71b57 u0 com.google.android.apps.nexuslauncher/.NexusLauncherActivity t75} 

    mFocusedActivity: ActivityRecord{fd61815 u0 com.a.a/.SetupWizardActivity t88} 
    mFocusedStack=ActivityStack{b84edc4 stackId=1, 1 tasks} mLastFocusedStack=ActivityStack{b84edc4 stackId=1, 1 tasks} 
    mSleepTimeout=false 
    mCurTaskIdForUser={0=88} 
    mUserStackInFront={} 
    mActivityContainers={0=ActivtyContainer{0}A, 1=ActivtyContainer{1}A} 
    mLockTaskModeState=NONE mLockTaskPackages (userId:packages)=0:[] 
    mLockTaskModeTasks[] 

答えて

0

ので、活動の余分なインスタンスが作成されましたA中onスタート。私はその場所を完全に見落としている。 onStartが呼び出されました。これは、Bが部分的に透明なダイアログであり、CがAを破棄したときに前面に表示されるためです。私はフラグを使用してこの問題を解決:

firstStartWizardIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
startActivityForResult(firstStartWizardIntent /* B */, DIALOG_FIRST_START_WIZARD); 

とバック標準にBのためlaunchModeを設定します。

関連する問題