Single Instance of Activity

后端 未结 2 1255
既然无缘
既然无缘 2020-12-11 05:19

My application has three activities say A -> B-> C.

Activity A is called from another activity through startActivityForResult(). Acti

相关标签:
2条回答
  • 2020-12-11 05:33

    You may be able to use a static variable to determine other data. I am not sure how much or what type of data you are looking to access from the other Activities, though.

    Also writing to persistent storage may work, but again - the vagueness of what data you are storing and how makes it difficult to answer. Just write/read the persistent storage in the onResume and onSuspend methdod of each Activity (or create super Activity class and extend it for A, B and C.

    0 讨论(0)
  • 2020-12-11 05:48

    Using android:launchMode="singleTask" is probably the best approach, since it won't recreate the activity if it's already running. Just add it to the activity in your AndroidManifest.xml, and you should be all set.

    <activity
        android:name=".MyActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
     </activity>
    

    Here's another question that might be useful: Android singleTask or singleInstance launch mode?

    0 讨论(0)
提交回复
热议问题