Intent serviceIntent = new Intent(this, MyService.class);
// serviceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startService(serviceIntent);
}
public void stop(View view) {
Intent serviceIntent = new Intent(this, MyService.class);
// serviceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
stopService(serviceIntent);
}
}
mian.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="start"
android:text="start service"
android:textSize="20dip" />
<Button
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="stop"
android:text="stop service"
android:textSize="20dip" />
</LinearLayout>
当我跑起项目,点击start service按钮,去触发onStart方法的时候,就报错了:
bad notification posted from package
请问是我的代码有问题吗?
其实我想做一个定时提醒用户上班的功能,想通过开机启动一个服务,然后通过AlarmManager去定时判断,到了设定的时间就弹出Notification提醒用户上班,我这样的思路有问题吗?
分数不多,请多过来帮帮忙,困扰了好几天了!
------解决方案--------------------Service无法弹出Notification,你可以在Service里发送个广播,在broadcast里接收广播并弹出Notification