android - how do i make a timer continue counting down after the app stopped? -


I have a class with a timer in it. When the method starts the timer and it goes forever, but when the app is completely closed, it stops and when the app is opened again it does not fall down. Is there a way to check whether the timer was previously ticked and ticked it with shared preferences or something else?

Method below

Public int shipAdd () {if if not, I know not.

(counter> = addSpend) {

  counter - = addSpend; AddSpend + = addSpend; CounterPerSec + = AddAmount; AddClick + = addClick; Test ++; // Under the new timer class count down the timer (Adetime, 1000) {Fineish on Public Zero () {Counter + = Admount; This.start (); } }.Start(); } And if (counter & lt; addSpend) {} ​​return addSpend;   

}

A great way to do this is to serve one. Calculates Public Segment Enhance Timer Service {@ Override Public IBinding On Bind (Intent Intent) {// TODO Auto-Generated Method Stub Returns Empty; } @ Override Public Wide On Create () {// Enter your Timer Code here}}

You want to start the service, to start using the service.

In an activity:

  startService (new intent (getApplicationContext (), CountDownTimer.class));   

in one piece

  getActivity (). StartService (getActivity (), CountDownTimer.class);   

Update your manifest with this line

  & lt; Service Android: name = "CountDownTimer" & gt; & Lt; / Service & gt;    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -