-2
我有一個鬧鐘應用程序 - 它適用於運行CM14我的摩托G3精絕,但字面上所有其他設備上我得到這個錯誤:從活動上下文之外調用startActivity() - 修復建議不工作
Unable to start service [email protected]b5bb9 with Intent { flg=0x10000000 cmp=joelizsoftware.david.slide_puzzle_alarm_clock/.RingtoneService (has extras) }: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
我從SO其次建議,並在補充說:
ringtoneIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
,但我仍然得到同樣的錯誤。有任何想法嗎?
public class Alarm_Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String extraString = intent.getExtras().getString("extra");
String prefString = intent.getExtras().getString("savePref");
Intent ringtoneIntent = new Intent(context, RingtoneService.class);
ringtoneIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ringtoneIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
ringtoneIntent.putExtra("extra", extraString);
ringtoneIntent.putExtra("savePref", prefString);
context.startService(ringtoneIntent);
}
}
它毀了我的星期天
移動'setFlags'線以下的'addFlags'線,並檢查它是否工作。 – MohanadMohie
但您未使用startActivity – Selvin