【发布时间】:2011-12-10 13:34:19
【问题描述】:
当我的 BroadcastReceiver 触发警报时,我正在尝试启动我的服务。我没有收到任何错误并且代码运行,但它没有启动我的服务并且我没有收到任何错误。这可能是我的服务或清单中的问题吗?
我注意到,当涉及到意图和上下文时,我经常遇到问题。我试图阅读它,但我找不到一个可以很好地解释它的网站。有什么建议吗?
public class Alarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
Intent myService = new Intent(BackgroundService.class.getName());
context.startService(myService);
}
}
******************清单************
<service android:name=".BackgroundService" android:process=":remote">
<intent-filter>
<action android:name="se.davidsebela.ShutMeUp.BackgroundService" />
</intent-filter>
</service>
<receiver android:process=":remote" android:name="Alarm"></receiver>
</application>
【问题讨论】:
标签: java android service android-intent broadcastreceiver