Search code examples
androidstartupandroid-sdk-2.3android-sdk-tools

How to open my android app at a start up of android mobile?


Possible Duplicate:
How to Start an Application on Startup?

I am new to android and I have my android app. I just want to open my app at start up of my android mobile. Plz tell me How to do this? I am using Eclipse with android sdk 2.3.3


Solution

  • If you want to do it pragmatically

    <receiver android:name=".MyServiceManager"
            android:enabled="true" >
    
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                     <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
    </receiver>
    

    then just add this code into application tag of your manifest file and add usages permission into manifest file.

    Then

    public class MyServiceManager extends BroadcastReceiver
    {
    
        @Override
        public void onReceive(Context context, Intent intent) {
    
            String action = intent.getAction();
    
            if(action.equalsIgnoreCase("android.intent.action.BOOT_COMPLETED"))
            {
                Intent myIntent=new Intent(context,package.YourActivity.class);
                myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(myIntent);
            }
    }   
    

    add this class into your project. Please check package name and class name and change it accordingly. If you still have problem then write me.