Search code examples
androidviewbackground-process

what is best approch to handle data when host Activity is not active


I have four activity Activity1,Activity2,Activity3,Activity4. Activity2 has some operation where we need to communicate with server that means we will send some request and according to request response will come.

  1. I click on button which will communicate with server in Activity2.
  2. Now i moved to Activity3 and Activity4.
  3. Still background process is happening for communication between server and client(android device).
  4. When i am at Activity4 , then Activity2 background process get finish.
  5. Now i come back from Activity4 to Activity3 and Activity2.
  6. Now i want, response should be appear form background process to Activity2.

What should be approach for this kind of use-case.?


Solution

  • In Activity2 On button click:

    1) use AsynchTask to fetch data.

    2) use startActivityForResult to start activity3.

    3) and onActivityResult you can check your result