Start New Activity After Few Seconds With Broadcastreceiver
I would like to start new activity after few seconds with BroadcastReceiver. New Activity needs to be started even if the app is closed in the meantime. For now I have this but not
Solution 1:
You can do something like this: (ignore this one)
int millis = 500;
new Handler().postDelayed(new Runnable() {
@Override
publicvoidrun() {
startActivity(new Intent(SplashScreenActivity.this, HomeActivity.class));
SplashScreenActivity.this.finish();
}
}, millis);
Update 1 (should work): Try this in your MainActivity, your probably counting time in wrong way so use calendar. If it works, I'll try to explain.
Intent intent = new Intent(this, Receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0); //Or you can get broadcast in your way.int seconds = 25;
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, seconds);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
Update 2: You should register your receiver in the manifest. In some cases there are intent filters on receivers but I it should work like that. Be sure that name of your package and receiver are correct.
<application...><activity...>
...
<receiverandroid:name=".package.YourReceiver"></receiver>
...
</application>
Post a Comment for "Start New Activity After Few Seconds With Broadcastreceiver"