1

enter image description here

Activity Startup shows a dialogue for edit or add new like in the snapshot

i have an activity like a user form , there is button to add signature of user which takes user to the next activity when signature was done then on button click on "Done" app jumps back to the user form activity but oncreate method is called of user form activity so all the data lost that was entered before going to the signature activity. it ahows Dialoguge box again

i use finish() after saving the signature but it reloads the previous activity. i also use onBackPressed(), it works for cancel button but not for save button. if i do save and call onBackPressed() it also reloads the user form activity, but if i just go to signature activity and press cancel button onBackPressed() works fine for this and also finish() works.

any suggestion please

i checked finishActivity() but it also not working

i just want that if i goto signature activity and return back the dialogue of edit or add new doesn't show. please help!

Malik Rizwan
  • 759
  • 1
  • 10
  • 31

1 Answers1

1

You need to save the state of the activity to do that ..

override onSaveInstanceState(Bundle savedInstanceState) and write the values you want to save, and receive them by overriding onRestoreInstanceState()

You can read more from this SO Question.

Use parcelable if you have lots of values.. This SO question was very usefull to me.

Community
  • 1
  • 1
Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41
  • thanks Kushal but, i have 20+ fields on form activity. its lengthy for me. any compact solution please ! – Malik Rizwan Jul 30 '15 at 10:46
  • You can use [Parcelables](http://stackoverflow.com/questions/7181526/how-can-i-make-my-custom-objects-be-parcelable) It will be a little extra code for first time. but i would suggest you go for it.. – Kushal Sharma Jul 30 '15 at 10:49
  • why onCreate of previous activty is called when i finish() the current activity any idea??? i also have pojo classes for values but i didn't want to do this i just want to stop calling of oncreate of previous activity on finsh() or do oter stuff. – Malik Rizwan Jul 30 '15 at 10:53
  • 1
    are you starting the sign activity by calling `startActivity(mIntetnt)` or `startActivityForResult(mIntent, requstCode)` ? – Kushal Sharma Jul 30 '15 at 10:58
  • i am using startActivity(mIntetnt) – Malik Rizwan Jul 30 '15 at 11:09
  • 1
    You should use startActivityForResult.. As you are passing some data back to the previous activity.. You will find good articles and SO questions with a quick google .. – Kushal Sharma Jul 30 '15 at 11:24