This is a strange behavior of Android Lollipop 5.0. I have two activities, A and B. A starts the activity B. When I click on the back button, in activity B, Android calls onCreate method on A. This behavior is observable only in Lollipop 5.0. In the other versions, onCreate is never called after finishing another activity.
What is the problem?
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<application
android:name=".Application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppThemeMaterial" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".activities.ActivityA"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.ActivityB"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/activityB" >
</activity>
</application>
</manifest>
What I think is happening is that when you leave the Activity
A
,onStop()
is being called on activityA
since its completely hidden andB
is on top of it.Usually now when you resume activity
A
after pressing backonStart()
is called and thenonResume()
.But, if you see the Activity LifeCycle, it is technically possible for
onCreate()
to be called as well, in the case where your app's process is killed by the system if other apps with higher priority need more memory.