私は今日少なくとも5時間以上これを達成しようと努力しています。ブロードキャストレシーバは、アプリケーションが終了したときにアクティビティを開始しません。
私はAlarmManagerを使用してアプリの呼び出し音を鳴らして、ちょっとした時計アプリをプログラミングしています。私のアプリが開いている、または最小化されているときにうまく動作します。私は、アプリケーションが閉じているときに動作させるようにしている、それは問題です。だから、AlarmManagerを設定するコードの一部がされています
AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(ctxt, AlarmService.class);
PendingIntent pen = PendingIntent.getBroadcast(ctxt, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.setExact(AlarmManager.RTC_WAKEUP, nextRing.getTime(), pen);
は(ここで、CTXTは文脈で、私はgetApplicationContext()とgetBaseContext()とnextRing.getTime(両方を試してみた)その長いです)その後、私は名前を説明するサービスであるように使用さウィッヒ(私のアラームサービスクラスを持っていますが、今BroadcastReceiverであると私はちょうど今それを名前を変更したくない
)日付を表す
public class AlarmService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
/*Intent cust = new Intent(context, CustomIntent.class);
context.startService(cust);*/
Bundle extras = intent.getExtras();
Intent newIntent = new Intent(context, AlarmActivity.class);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.putExtra("AlarmName", extras.getString("AlarmName"));
context.startActivity(newIntent);
}
}
これはBroadcastReceiverだけで試したもので、obviouは動作しませんずるいので、私は次のコード
public class CustomIntent extends IntentService {
public CustomIntent() {
super("CustomIntent");
}
@Override
protected void onHandleIntent(Intent intent) {
Intent newIntent = new Intent(getBaseContext(), AlarmActivity.class);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(newIntent);
}
}
を持ってIntentService(上部のコメントアウトコード)を追加しようとしました...そして、それはどちらか動作していませんよ! (非常に)長いポスト申し訳ありませんが、私は私が試した何かを説明する必要があり、私はタフな
<application>
[Here goes stuff that have nothing to do with my bug]
<receiver android:name=".custom_classes.AlarmService"/>
<service
android:name="com.group9.abclock.custom_classes.CustomIntent"
android:enabled="true" >
<intent-filter>
<action android:name="com.group9.abclock.custom_classes.CustomIntent" />
</intent-filter>
</service>
</application>
:最後に、ここで私が使用してマニフェストです。あなたが助けることができれば、事前に感謝します!
私は、PendingIntent.getService()とCustomIntent(Serviceを拡張するIntentServiceを継承する)を使用して呼び出しました。それは私のアプリが実行されているときに正常に動作します(私はその部分の仕事をする印象的な数を見つけました)が、私はそれを閉じても活動はありません... どのように正確なのですか?秒は大丈夫ですが、私の場合は分ではありません(それはかなりうまくいくようです) –
[編集]:あなたのリンクを読んで、現在のlvl apiは21です。確かに、私はsetExactAndAllowWhileIdle()を使用しました。アイドル時に発火しますが、閉鎖時にバグを修正していません –
アプリケーションを終了した後、実行中のプロセスを見て、まだサービスが実行されているかどうかを確認しましたか?パッケージが存在しない場合は、このメソッドを呼び出すことはできません。これが当てはまる場合、サービスはアプリケーションと一緒にシャットダウンしているので、何とかそれらを分離する必要があります。 –