I can reproduce the issue with some of my projects but clean project with no code (hello world text only) works fine:
the main activity will start, press back button, Activity.onStart()/onStop()
will be called once (normal)
then open the app again from device itself (the process is still alive, of the app which was started from studio) and then again press back button, Activity.onStart()/onStop()
will be called twice...
Works fine with Android Studio Giraffe and if the app (process) was initially started from the phone directly instead of Android Studio Hedgehog's run.
Does anyone noticed it in the existing projects?
Updated
Another case was:
start the app from Android Studio Hedgehog
the main activity will start, press back button and you may notice that you need to do it multiple times because for some reason there 2-3 instances of launch activity were started
or instead of pressing back button I press home button (onPause
, onStop
will be called) and then return to the app from main launcher again but for some reason it will call onCreate
, onStart
, onResume
- basically starting a new activity, instead of resuming the current one which is still alive - onStart
, onResume
For some reason it was caused by <category android:name="android.intent.category.DEFAULT" />
(a clean project doesn't have it):
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I removed it and it works fine now:
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This issue has never been happening with previous releases of Studio, and yeah, it happens only when you install the app to the device from Android Studio (RUN) button. So it doesn't effect users (Google Play). But development with that bug was a headache.
p.s. this insane, I spent a lot of time trying to find out what was the issue...
p.s. tested devices: Samsung S22 Ultra (Android 14), Samsung S10 (Android 12)