Reputation: 18754
I tried some of the solutions I have found online for launching my activity on boot. Currently I have:
Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name="App_Receiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Main Activity:
public void onReceive(Context context, Intent intent) {
if ((intent.getAction() != null) && (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
{
// Start the service or activity
Intent startActivity = new Intent();
startActivity.setClassName("org.package_name", "org.package_name.MainActivity");
startActivity(startActivity);
}
}
However, when I boot the phone I get the error that my app was stopped in an unexpected way (i.e. crashes). What am I doing wrong any ideas ? (Testing on Android 2.2, API 8)
Upvotes: 0
Views: 165
Reputation:
Like the answer posted above: it needs permission, and:
startActivity.setClassName("org.package_name", "org.package_name.MainActivity");
Make sure you have declared that Activity public in Manifest file, also please provide a stack trace to see the problem exactly.
An example for the activity declaration in manifest:
<activity
android:name=".MainActivity"
android:label="@string/app_name">
</activity>
Upvotes: 0
Reputation: 56925
Boot completed requires the android.permission.RECEIVE_BOOT_COMPLETED permission.
Edit Please write package name with receiver name.
<receiver android:name="org.package_name.App_Receiver">
Intent startActivity = new Intent(context, MainActivity.class);
startActivity(startActivity);
Upvotes: 1