I was wondering if it's possible (and if it is how) to start up my app at a specific time, something like an alarmclock which goes off at a specific time. Let's say I want my app to start up at 8 in the morning, is that feasable ?
Starting application on a schedule can also be achieved by AutomateIt app. Timer can be set and the app you choose will launch at a specific time.
It is important to check that the first activity which opens when the app is launched is MainActivity. java (The activity which we want to appear only once). For this, open the AndroidManifest. xml file and ensure that we have the intent-filter tag inside the activity tag that should appear just once.
Load only the data necessary for rendering the first frame, and delay the rest until after launch. Refreshing data, for instance, may be possible to defer until after the app has launched. Use placeholder content for items not critical for launch: Retrieve only the data necessary to display the app's initial view.
You can do it with AlarmManager, heres a short example. First you need to set the alarm:
AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE); Date futureDate = new Date(new Date().getTime() + 86400000); futureDate.setHours(8); futureDate.setMinutes(0); futureDate.setSeconds(0); Intent intent = new Intent(con, MyAppReciever.class); PendingIntent sender = PendingIntent.getBroadcast(con, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); am.set(AlarmManager.RTC_WAKEUP, futureDate.getTimeInMillis(), sender);
Next, You need to create a reciever with some code to execute your application: (ie- starting your app):
public class MyAppReciever extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { startActivity(new Intent(context, MyAppMainActivity.class)); } }
You are probably looking for AlarmManager, which let's you start services / activities / send broadcasts at specific intervals or a given time, repeating or not. This is how you write memory friendly background services in android. AlarmManager
is sort of like cron in unix. It allows your background service to start, do its work, and get out of memory.
You probably do not want to start an activity (if that's what you meant by "application"). If you want to alert the user that something has happened, add an alarm that starts a receiver at a given time, and have the receiver add a notification. The notification can open the application when clicked. That's less invasive than bringing some potentially unwanted activity to the foreground.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With