Issue
In my app I have an activity as shown in image below [![enter image description here][1]][1]
If I click the button "Add Patient" it will redirect to another activity. As shown in image below
If I click the home button in "NewPatient" activity it shows "My Patients" activity and "NewPatient" activity disappears.Can you please suggest how to retain "NewPatient" activity when home button is pressed when app is in "NewPatient" activity.
Manifest im using :
<activity
android:name=".activity.patient.PatientsActivity"
android:parentActivityName=".activity.MainActivity"/>
<activity
android:name=".activity.patient.PatientFormActivity"
android:parentActivityName=".activity.patient.PatientsActivity" />
Solution
The first solution. Launch mode based.
You can move "My Patients" activity in front of "New Patient" activity.
- set android:launchMode="singleTask" to "My Patients" at manifest
- Override
onBackPressed()
method of "New Patient" activity, and start "My Patients" from it, without calling super.
You can read more about launch modes here.
The second solution. Bundle based
- Start "New Patient" activity for result from "My Patients" activity.
- Override
onBackPressed()
method of "New Patient" activity, and save your data to intent, as you save it to Bundle inonSaveInstanceState
. - Provide saved data to "My Patients" activity via calling
setResult
, before callingsuper.onBackPressed()
- Handle saved data inside
onActivityResult()
of "My Patients" activity - Start new instance of "New Patient" activity from "My Patients" activity with saved data.
The second one is more appropriate and less painful.
Answered By - Ufkoku
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.