I am creating an app that contains an alarm. When the alarm triggers it should start a new activity, but it only shows 'Unfortunately application has stopped'.
Even the doesn't say anything. Here is my code:
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.media.MediaPlayer;
import android.provider.Settings;
public class AlarmReceiver extends BroadcastReceiver {
private MediaPlayer mp;
@Override
public void onReceive(Context arg0, Intent arg1) {
Intent i = new Intent(arg0, aani.class);
arg0.startActivity(i);
}
}
Thanks in Advance
Because you need to add the flag to create a new task:
Intent i = new Intent(arg0, aani.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(i);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.