我想service
在手机完成启动时启动(CheckTime)。这似乎可行,但我的应用程序立即崩溃。我收到以下错误“ java.lang.RuntimeException: Unable to start receiver com.example.alarmtest.MyReceiver: java.lang.UnsupportedOperationException: Not yet implemented
”。我试图解决这个问题没有成功。我不确定我是否遗漏了一些东西manifest
(我对 android 开发相当陌生)。这是我的 MyReceiver 代码。(出现 log.d )
public class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, CheckTime.class);
context.startService(startServiceIntent);
Log.d("evan alarm", "Started on Launch, android autostart");
throw new UnsupportedOperationException("Not yet implemented");
}
}
和 CheckTime 的代码(log.d 永远不会出现)
public class CheckTime {
public void loglab(){
Log.d("evan alarm", "We are now in CheckTime");
}
}
最后是清单。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alarmtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service
android:name="com.example.alarmtest.MyService" >
<intent-filter
android:label="com.example.alarmtest.MyService">
</intent-filter>
</service>
<service android:name="com.example.alarmtest.CheckTime" />
<activity
android:name="com.example.alarmtest.AlarmActivity"
android:label="@string/title_activity_alarm" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.alarmtest.ChangeTime"
android:label="@string/title_activity_change_time" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.AlarmTest.AlarmActivity" />
</activity>
<receiver
android:name="com.example.alarmtest.MyReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>