Re: [android-developers] Re: When the new activity starts, the data of previous activity is gone.
Hi Pranav,
The way in the previous mail has an issue: if user inputs sth. in Current activiy named Activity2, then Presses "Prev", the previous Acitivy named Activity1 does keep the inputed contents in UI, however when user presses "Next" here to go to Activity2, Activity2 will not keep the data inputed by user.
Another solution: Construct a Class for your registration info i.e. Person which implements Serializable interface.
1. For each activiy, implements the 2 buttons' logic like this:
next.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
update person according to the cotents inputed by user
Intent i = new Intent();
i.setClassName(the name of the next activity.....);
i.putExtra("Person", person);....... //to pass this activity's data to next
startActivity(i);
finish(); }});
previous.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
update person according to the contents inputed by user
Intent i = new Intent();
i.setClassName(the name of the previous activity.....);
i.putExtra("Person", person);....... //to pass this activity's data to next
startActivity(i);
finsh(); }});
Of course, special logic is needed for the first activity's Back button & the last activity's Next button;
2. Add below code in OnCreate() :
Intent i = getIntent();person = (Person)i.getSerializableExtra("Person");if(person != null) {update the editable ui controls according to the value of person's member variables} else {
person = new Person(); // this will only happen in the first activiy}
3. For the back key handle, use the same logic as Prev button to set onKeyListener for the activiy.
BRs,
Rui
2010/1/1 Rui Wu <netiger198610@gmail.com>
Hi Pranav,I guess you implemented your logic like this:Button previous = (Button) findViewById(.....);previous.setOnClickListener(new OnClickListener(){public void onClick(View v) {Intent i = new Intent();i.setClassName(the name of the previous activiy.....);startActivity(i);}});Try the below way:Button next = (Button) findViewByid(.....);next.setOnClickListener(new OnClickListener(){public void onClick(View v) {Intent i = new Intent();i.setClassName(the name of the next activity.....);i.putExtra();....... //to pass this activity's data to nextstartActivity(i);}});Button previous = (Button) findViewById(.....);previous.setOnClickListener(new OnClickListener(){public void onClick(View v) {finish();}});What you need to do is passing the current activity's data to next Activity; When you press the Prev button, you will find Android keeps the inputed strings in the EditText and other editable views automatically.......Hope this can help you.2009/12/31 android09 <pranav.jajal09@gmail.com>Hi Neilz,Thank you for reply me with the proper and useful idea. I tried tohold the first activity data but it gives error while loading thedata. It is not allows me to get data back.Can you understand me by the code? How can i hold the first activity'sdata when i start another activity and get back to previous. I alsotried with the onPause() and onResume() methods. How can i do thatwith the code? Please help me.Thank you.Regards,---------------Pranav--You received this message because you are subscribed to the GoogleGroups "Android Developers" group.To post to this group, send email to android-developers@googlegroups.comTo unsubscribe from this group, send email toFor more options, visit this group at
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home