Reputation: 1539
I have an android application that displays a toast every hour and then every 2 hours I want a new screen to be displayed which I'm assuming is done by calling a new activity.
The timer im using is a chronometer and this is the code I have so far for it:
Chronometer.OnChronometerTickListener mChronoListener = new OnChronometerTickListener() { // listens to journey timer to initiate time based events
int alertTime = 10000;
int breakTime = 20000;
public void onChronometerTick(Chronometer arg0) {
long elapsedTime = SystemClock.elapsedRealtime() - arg0.getBase();
if (elapsedTime > alertTime)
{
Toast.makeText(SafeDrive3Activity.this, "HOUR PASSED", Toast.LENGTH_LONG).show();
alertTime += alertTime == 10000 ? 10000 : 10000;
}
if (elapsedTime > breakTime)
{
//call activity2?
}
}
};
Basically I want the new screen to display some text, a new timer andm a button so it will need to have a completely different design to the main activity.
I'm not sure what code to put in the if statement above to call a new activity or if thats a valid way of doing it.
With the new activity, do I need to create a new mail.xml file as well?
Any help with this would be greatly appreciated!
Upvotes: 1
Views: 108
Reputation: 34765
if (elapsedTime > breakTime)
{
//call activity2?
startActivity(new Intent(getApplicationContext(),NextActivityToLoad.class));
}
Use this an try...
Upvotes: 2
Reputation: 1876
If you have a context, you simply do context.startActivity(intent);
Make sure the intent you use has the START_TASK flag set.
Upvotes: 1