Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I be sure that Android application finished running by checking isFinish() in the main Activity's onPause()?

I have to clear some application data after my application is finished running.As far as I know onDestroy() may not be called. So I decided to check if isFinishing() == true in onPause() of the root activity to see whether this activity and other ones of my app are in the process of finishing. But I doubt if this activity:

  <activity
        android:name="com.test.AuthorizationActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

will be a root activity? And is this a correct way in general?

like image 383
Oleksandr Karaberov Avatar asked Nov 12 '22 09:11

Oleksandr Karaberov


1 Answers

I think you need to rethink your design because it seems that it isFinishing is true only when finish is called on the activity and does not account for cases where the activity is destroyed because of low memory.

From the docs:

This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

For what you are suggesting you could possibly store the application's state data in static variables, which will be cleared when your application process ends (when the last activity/ service is finished).

like image 109
Emil Davtyan Avatar answered Nov 14 '22 21:11

Emil Davtyan