Mick
Mick

Reputation: 1219

Update View with updated data in Android

I am noob in Android. Suppose I have two Activity in my android app.

Activity A and B, currently I am on Activity A then on click on one button I am now Activity B. Here From Activity B I want to update some view with updated data that is in Activity A. I got updated data in Activity B so Should I use here LocalBroadCastReceiver for this or anything ?? so that When I press back then app should show me updated data in Activity A

Should we use our custom callback here to update the UI view data of Activity A from Activity B ??

Upvotes: 0

Views: 153

Answers (2)

r4jiv007
r4jiv007

Reputation: 3104

okay , there are multiple ways to do it :-

  1. you can use a static variable to store you data that too of application level ( might not be a good approach ) check the value of vairable in onResume() and set it to the view.
  2. you can use sharedpreferences if your data is not that large , store the data in Activity B and fetch it on onResume() method of activity A.
  3. as @nikis has told you
  4. if your data is too large store it in db.

I dont think broadcastreceiver fits right in your scenario !!

Upvotes: 1

nikis
nikis

Reputation: 11234

No, you shouldn't use BroadcastReceiver for that. The method depends on the size of data you want to transfer from Activity B to Activity A. If it's quite small, you can start Activity B with startActivityForResult and then get data back at the onActivityResult method (in Activity B you should use setResult once you are done). If the size of data is quite big, it's better to use DB for storing it instead of keeping it in memory.

Upvotes: 2

Related Questions