android - How to keep running timer with service? -
i have problem services hope me. have countdown timer in activity , want keep running service. when copy codes compiler shows nullpointerexception. please me. codes these:
public void setmytimer(){ countdown.start(86400); countdown.setoncountdownendlistener(new countdownview.oncountdownendlistener() { @override public void onend(countdownview cv) { if (m == 0) { = + 1000000; if (a == 366000000) { = 0; snackbar snackbar = snackbar.make(coordinator, "game over", snackbar.length_long); snackbar.show(); cv.stop(); } else { m = m + a; money.settext(string.valueof(m)); cv.start(86400000); } } else { snackbar snack = snackbar.make(coordinator, "you ddin't spend money", snackbar.length_long); snack.show(); } } }); }
and service class's codes are:
public class timerservice extends service { private mainactivity mainactivity = new mainactivity(); @nullable @override public ibinder onbind(intent intent) { return null; } @override public int onstartcommand(intent intent, int flags, int startid) { mainactivity.setmytimer(); return start_sticky; }
}
if codes ruins sorry because beginner yet.
you cannot create activity
via call new
, managed framework based on intents
. same thing service
. separate components , should not contain direct references other.
i'd suggest walking through course on basic android development , java in order past issues , more familiar framework.
Comments
Post a Comment