Show images one by one after 1 minute

92 Views Asked by At

Sorry if iam not able to give accurate title to my question Iam Working on an android game in which i have a fuel bar i.e 10 random vertical lines make a fuel bar in my game case. When a player taps on rematch,the game then One fuel bar became gone i.e 9 left. Same way if rematch happen 10 times then fuel bar is empty Now what i need to do is IF a player rematch the game 5 times then fuel bar would be 5 and if he close the app, comes back after 5 minutes again then the fuel bar should be again 10. i.e I wanted to increase one fuel bar after every minute. What exactly i have to do keeping in view that shared preference will also be used. Any link or example would mean alot to me

Here is my onclick for rematch button

    if(fuelcount==9)
    {
        lifefuel.setImageResource(R.drawable.batterynine);
    }
    else if(fuelcount==8)
    {
        lifefuel.setImageResource(R.drawable.batteryeight);
    }
    else if(fuelcount==7)
    {
        lifefuel.setImageResource(R.drawable.batteryseven);
    }
    else if(fuelcount==6)
    {
        lifefuel.setImageResource(R.drawable.batterysix);
    }
    else if(fuelcount==5)
    {
        lifefuel.setImageResource(R.drawable.batteryfive);
    }
    else if(fuelcount==4)
    {
        lifefuel.setImageResource(R.drawable.batteryfour);
    }
    else if(fuelcount==3)
    {
        lifefuel.setImageResource(R.drawable.batterythree);
    }
    else if(fuelcount==2)
    {
        lifefuel.setImageResource(R.drawable.batterytwo);
    }
    else if(fuelcount==1)
    {
        lifefuel.setImageResource(R.drawable.batteryone);
    }
1

There are 1 best solutions below

4
On

As you said, you could use the shared preferences to store the the time of the last fuel bar change.

Also, you should read about the Android lifecycle, and understand how to use methods such as "onPause", "onResume", etc.. http://developer.android.com/training/basics/activity-lifecycle/pausing.html

In the end, the goal is to have your application recalculate the fuel-bar every time it is continued.