-1

I'm trying to write an app like a memo. First here is a listView in the A_activity. And I have second activity named B_activity to do the memo. I put a button in the A_activity and use it to Add a memo. So, I use intent to switch A_activity to B_activity.

Now here is the problem:
I use the same way to switch B_activity back to A_activity with a bundle stored the values. I want the result is the listView would add a memo I just create and the old memo will remain. But all failed. I know how to do but dont know how to write the code. Can someone give me some example?

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
Edison
  • 79
  • 1
  • 13
  • please formulate clearer what you want to achieve. I think you are misunderstood by most people reading your question because of the misleading title. – Obl Tobl Feb 19 '13 at 14:20
  • im sorry , im not good at English. I know, but I want to try write something like memolist. A list of memos in A and if I want to add or modify the memo I click the button to B to change or add the value. And back to A when I finished. this is all I want to do. – Edison Feb 19 '13 at 14:33
  • and...what's the problem exactly if you just want to switch the activities? finish the first and start the second and the other way round. Maybe someone can help you if you post some code. – Obl Tobl Feb 19 '13 at 14:36
  • ok. i will update when I back to the office. – Edison Feb 19 '13 at 14:38

2 Answers2

3

In your A activity before passing data to listView check if bundle is null.

ex -

Bundle bundle = getIntent().getExtras();
if(bundle != null)
{
    // pass your values to listview
} else {
    return;
}

Instead use startActivityForResult(); method for these kind of operations.

Hisham Muneer
  • 8,558
  • 10
  • 54
  • 79
1

If I right understand, you send Intent from A to B and after some logic send Intent from B to A, and do it many times. If I am rigth it is very awful method. Your activity's stack will be populated and back button will work not correct. I think you should use startActivtyForResult() from A and setResult() in B. I hope I am right. In this way you can pass Bundle from A to Intent and return Bundle to onResult();

Good luck!

Ilya Demidov
  • 3,275
  • 2
  • 26
  • 38
  • I know, but I want to try write something like memolist. A list of memos in A and if I want to add or modify the memo I click the button to B to change or add the value. And back to A when I finished. – Edison Feb 19 '13 at 14:32
  • Is anything can do this ? – Edison Feb 19 '13 at 14:33
  • Ok I see. And where is problem?) – Ilya Demidov Feb 19 '13 at 14:33
  • The last step back to A with some value failed. the memolist clean all the old memo. – Edison Feb 19 '13 at 14:37
  • in the onCreate of your first activity, try the answer from @Hisham Muneer. If you do it right this will work – Obl Tobl Feb 19 '13 at 14:38
  • http://stackoverflow.com/questions/4096169/onsaveinstancestate-and-onrestoreinstancestate check this topic. Its for your problem. You should save your data in onSaveInstanteState and restore it in onCreate or onRestoreInstanteState(). – Ilya Demidov Feb 19 '13 at 14:39