Following is my use case:
User click on App icon -> MainActivity ->FirstActivity-> SecondActivity
SecondActivity has three fragments i.e. F1, F2, F3
Suppose user is on F1 in SecondActivity, now if user minimizes the app by pressing home button, and then re-launches the app not using App icon but by selecting from the list which gets displayed by long press (don't know the technical name of that )
I have already explored most of the questions and even tried following approach
How to make an android app return to the last open activity when relaunched?
(but this seems to work, in case when i want to re-launch my app from app icon i.e. from launcher):
Following is my activity and fragment lifecycle method invocation logs:
When i minimize the app:
- E/SecondActivity﹕ onPause called
- E/F1﹕ On Pause
- E/F1﹕ OnSaveInstanceState
- E/SecondActivity onStop called
On re-open app:
- E/FirstActivity﹕ onRestart called
- E/FirstActivity﹕ onStart called
- E/FirstActivity﹕ onResume called
- E/SecondActivity﹕ onDestroy called
- E/F1﹕ On Detach
- E/FirstActivity﹕ onPause called
- E/FirstActivity﹕ onStop called
As per my understanding this should work like following:
- onPause of SecondActivity, I need to save the current visible fragment in shared pref
- onResume of SecondActivity, I need to pull the fragment name and display that using fragmentManager
But after re-opening app my SecondActivity onResume doesn't gets invoked, instead FirstActivity's onRestart gets called and onDestroy of SecondActivity gets called (as shown above)
After trying lot of options and reading several SO solutions, I am unable to sort this out.
Please suggest, how to handle this, thanks in advance.
Edit:
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".controller.ApplicationLoader"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:alwaysRetainTaskState="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegistrationActivity"
android:label="@string/title_activity_registration"
android:noHistory="true"
android:screenOrientation="portrait"/>
<activity
android:name=".HomePageActivity"
android:label="@string/title_activity_home_page"
android:noHistory="true"
android:screenOrientation="portrait">
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<service
android:name=".services.BgService"
android:exported="false"
android:process=":remote" >
<intent-filter>
<action android:name="com.example.bgapp.BackgroundService" />
</intent-filter>
</service>
<receiver android:name=".services.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".ProductOverviewActivity"
android:screenOrientation="portrait">
</activity>
<receiver android:name=".receivers.SmsReceiver"
android:screenOrientation="portrait">
<intent-filter android:priority="99999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<!-- Intent service -->
<service
android:name=".services.WService"
android:exported="false" />
<service android:name=".services.VerifyService" android:exported="false"/>
</application>
</manifest>