user1169079
user1169079

Reputation: 3083

Why my Activity is not starting when phone starts?

I have used Broadcast receiver when it restarts it shows the launcher screen but doesnt start my default home automatically...I had to choose my activity to start ...how to launch my activity automatically ? ... Here is my androidmanifest.xml

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
     >
     <receiver android:name=".receiver.onPhoneReceiver">
     <intent-filter>
     <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
     </receiver>

    <activity
        android:name=".DisableHomeActivity"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 
       <intent-filter>
         <action android:name="android.intent.action.MAIN" /> 
             <category android:name="android.intent.category.HOME" />                                
              <category android:name="android.intent.category.DEFAULT" />                         
       </intent-filter>
    </activity>
</application>

Upvotes: 3

Views: 626

Answers (2)

Yugandhar Babu
Yugandhar Babu

Reputation: 10349

For creating Home screen application, no need to use BroadcastReceiver. The activity with action and categories you used are sufficient. After power ON the android system will display all apps with category HOME and DEFAULT in a list, you have to select your home screen app and make it as default by checking the checkbox below the list, so from next time onwards it won't ask you to select home app whenever you press HOME button.

Check the Android example Home Sample , it may help you to create a new Home Screen application.

Upvotes: 1

Lucifer
Lucifer

Reputation: 29672

You need to you following code in BroadcastReceiver,

public void onReceive(Context context, Intent intent)
{
    System.out.println ( "Application Started" );
    // put your TimerTask calling class here

    try
    {
        Intent myIntent = new Intent ( context, AutoStartExampleActivity.class );
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(myIntent);
    }
    catch ( Exception e )
    {
        System.out.println ( " Error while Starting Activity " + e.toString() );
    }
}

You can download an example for here.

Upvotes: 0

Related Questions