androidandroid-activitylauncherlaunching-application

How to start/ launch application at boot time Android


I would like to launch my app when my tablet starts, so that the main activity of my app is the first thing that the user see when they start the tablet.
I've read about LauncherActivity but I don't understand how to use it.
Can anyone help me with suggestions, links or tutorials for this?
Is LauncherActivity the best way or are there alternatives?


Solution

  • These lines of code may be helpful for you...

    Step 1: Set the permission in AndroidManifest.xml

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    

    Step 2: Add this intent filter in receiver

    <receiver android:name=".BootReceiver">
        <intent-filter >
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>
    

    Step 3: Now you can start your application's first activity from onReceive method of Receiver class

    public class BootReceiver extends BroadcastReceiver {
    
       @Override
       public void onReceive(Context context, Intent intent) {
           Intent myIntent = new Intent(context, MainActivity.class);
           myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           context.startActivity(myIntent);
       }
    
    }