Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to start app immediately after the boot completed

Tags:

java

android

I need to know why my app didn't run immediately after booting in android real phone? My app runs but after a few second of booting.

My Code is

public class AutoStart extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
         if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
                Intent i = new Intent(context, MyActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
    }

}

My activity is running, but after few Seconds of the boot completed. Is it Possible to reduce this few second?

I want to run my app immediately. I Don't want to allow user to access the phone.

like image 702
Karan Mavadhiya Avatar asked Jun 05 '13 06:06

Karan Mavadhiya


2 Answers

This can increase you priority but still there would be some delay. Since android first load its OS and the all the other activity starts.

<receiver
    android:name=".AutoStart"
    android:enabled="true"
    android:exported="true"
    <intent-filter android:priority="1000">
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>
like image 189
Ayush Avatar answered Nov 05 '22 10:11

Ayush


I run through this problem too. To anyone still searching for solution:

I want to run my app immediately. I Don't want to allow user to access the phone.

Consider turning your app into home launcher. Make changes in the manifest:

Add to your activity

android:launchMode="singleTask"

Add to intent filter in activity

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />

After that it will launch immediately with system, not showing to user anything else.

like image 29
Krzysztof Wiśniewski Avatar answered Nov 05 '22 08:11

Krzysztof Wiśniewski