-2

I want to refresh my HomeScreenActivity so you can see your balance when you have paid (it works with NFC/HCE).

When you scanned your phone you go back to the HomeScreenActivity. The problem is that when you go back, your balance button is not updated so you have your old balance. You get your new balance when you go back to the login activity and then login again.

I tried a lot to fix this but nothing seems to work. Maybe the problem is that the communication with your balance goes from a database/API.

I hope someone can explain me or fix the problem!!

P.S. I do not have a adapter for balance!

Rick Mkl
  • 1
  • 4
  • @KailasBhakade I know when to use notify data set changed but the problem is i dont have an adapter for my balance so I want to know if you can use notify data or something else to reload that activity where you are going to. – Rick Mkl Jun 02 '17 at 10:28

3 Answers3

0

Please use onActivityResult method for the actvity where you want to refresh the amount. And in onActivityResult method reset the adapter and call notifyDataSetChanged().

parbir
  • 31
  • 2
0

You have many way to do this. You can research about onActivity result, it will help you solve this problem. EventBus, observer is the same solution.

  • I will give it a try. Thanks for the help! – Rick Mkl Jun 02 '17 at 10:29
  • onActivity result run when another activity finish with result code and back to homescreenactivity. EvenBus and observer have same logic but on your custom function. If you have any problem or you have result, please tell me ^_^ – Nguyễn Gia Lễ Jun 02 '17 at 10:34
0

You have a lot of ways to make your data always up-to-date: I will list some of them:

  • Use Realm for your local DataBase. It have own classes extending recyclerviewAdapter and other to notify you when data in tables was changed.
  • Use new Android Room library it also can do the same thing using LiveData
  • Use RxJava to subscribe to some changes in you app. When changes will happen Rx will emit new item to all subscribers.
  • User Observer OOP pattern

NotifyDataSetChanged doing the same thing. When you expect your container data to be changed you call this method and RecyclerView.Adapter will rebind all existed ViewHolders to new data.

These are not all possible variants to organize notifications. You can also use EventBus or kind of timer to refresh data with specified delay(this isn't the best one).

Anton Kazakov
  • 2,740
  • 3
  • 23
  • 34
  • Thank you so much, i will lookup for these ways. – Rick Mkl Jun 02 '17 at 10:40
  • Thanks, do you know if RxJava works when there is something changed in a database? – Rick Mkl Jun 02 '17 at 10:42
  • @RickMkl yes it is. Realm database provide method to observable which will emit items to subscribers/ Room - ORM over Sqlite can also return your data from Database wrapped into Flowable(RXJava 2 type) – Anton Kazakov Jun 02 '17 at 10:46