Issue
I will explain my problem on basic case. Assume I have 2 activities, A and B. They have 1 EditText and 1 Button both. Buttons are for navigate between activities. EditTexts are for holding the data. Assume EditTexts are filled in both activities, but when I click to any of the button, I don't want to lose data of EditTexts. I have method onClickListener() for buttons;
for button in A:
Intent intent=new Intent(A.this, B.class);
startActivity(intent);
for button in B:
Intent intent=new Intent(B.this, A.class);
startActivity(intent);
But when I click buttons, EditTexts texts are disappearing. I need help for keeping the data. Thanks in advance for all replies.
Solution
If you just want to flip back and forth between the 2 activities, you can do the following:
When you want to go from A
to B
, do this:
Intent intent=new Intent(A.this, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
This will take an existing instance of B
and rearrange it so that it is now on top of the task stack (ie: shown to the user). The existing instance of A
is now underneath it.
In B
, to go to A
, modify the code with the same additional line to add the REORDER_TO_FRONT
flag.
Keeping data in EditText
is not a good or robust "persistency" solution, but for simple applications it can certainly be used for that.
Answered By - David Wasser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.