Assume that MainActivity is the start up Activity.
We need to add a new class extended from BroadcastReceiver to accept the broadcasted messages.
public class BootUpReceiverClass extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
Then, we need to add a permission in AndroidManifest.xml.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
After that, we can a receiver tag within <application> </application>
沒有留言:
張貼留言