0

I hope you All understand with my case. For example, I have 3 food to cook :

{
"response": [{
        "food": "burger"
    },
    {
        "food": "pizza"
    },
    {
        "food": "potato fried"
    }]

}

I put the food in a List. When one food click, there will another Activity. In this Activity there are two button Start and Stop. I want to know :

  • How to handle every Stop button cannot click until Start button clicked. But when the App let say Force Stop manually by user, the session of Buttons still there.

I have many many many Food in my App and I think to save the Session in Shared Preference will take more effort. Is there any way to do this? Or Shared Preferences is a must in my case? I need an Advice the way which better for my App perfomance. Thanks in Advance

MrX
  • 953
  • 2
  • 16
  • 42

2 Answers2

1

You should use SQLite database to do your task. Now for managing session for button for each food, Create a table say FOOD_TABLE and add column like: ID, NAME, STATUS so when fetch data from API store all data in your sqlite DB table in that set STATUS value to zero, when you click on start button for a particular food, update STATUS to 1 via update query, when you stop it update again STATUS to 0.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
  • How if my list refreshed? I have a refresh button on my list – MrX Jan 11 '18 at 03:23
  • If a list is refreshed all data will be wiped out you have to get them from API, another approach is you can get all data from sqlite which have the state maintained via STATUS column, it up to you what you want. – Suraj Vaishnav Jan 11 '18 at 03:42
  • how if user clear data?In my knowledge, sqlite will create a file into internal memory device `.db` right? – MrX Jan 11 '18 at 10:44
  • Yes but clearing data means you are resetting app like fresh install, so even if user logged in, will be logout immediately and also app killed automatically when you click on clear data.So you don't have to worry about clear data – Suraj Vaishnav Jan 11 '18 at 12:38
0

Finally, I use Shared Preferences to handle the timer and session. First, I keep the lasttime and save it into Shared Preference if let say current timer activity is close (burger activity). When the last record click again (burger activity), I get the lasttime value from Shared Preference and I use this to start again the timer. From it, I can check if lasttime available, activity will show the start button only or vice versa for stop button.

MrX
  • 953
  • 2
  • 16
  • 42