質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
アプリをキルしても動的に表示し続ける通知を作ろうとしています。
|
4
4
|
|
5
5
|
そのため下記のように onStop時にServiceクラスに移行し、同時にSetNotificationクラスをServiceクラスに渡そうとしています。
|
6
|
+
[こちら](http://android-note.open-memo.net/sub/activity__pass_my_class.html)を参考にしました。
|
6
7
|
|
7
8
|
※Serviceクラスとはプログラム内で明示的に停止させない限り、アプリをキルしてもバックグラウンドで動き続ける特殊なクラス
|
8
9
|
```kotlin
|
1
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
val serviceIntent = Intent(this, NotificationService::class.java)
|
14
14
|
serviceIntent.putExtra("key1", setNotification)
|
15
|
-
startService(serviceIntent)
|
15
|
+
startService(serviceIntent)
|
16
16
|
}
|
17
17
|
```
|
18
18
|
受け取り側(Serviceクラス)
|
@@ -52,9 +52,9 @@
|
|
52
52
|
しかしonStopを実行してみるとエラーが発生して通知が表示されないです。
|
53
53
|
```Logcat
|
54
54
|
--------- beginning of crash
|
55
|
-
2022-04-19 16:09:41.613 19443-19443/com.
|
56
|
-
Process: com.
|
57
|
-
java.lang.RuntimeException: Unable to stop activity {com.BSCreate.cpubatteryindicatorinstatusbar/com.
|
55
|
+
2022-04-19 16:09:41.613 19443-19443/com.Create12c.cpubatteryindicatorinstatusbar E/AndroidRuntime: FATAL EXCEPTION: main
|
56
|
+
Process: com.Create12c.cpubatteryindicatorinstatusbar, PID: 19443
|
57
|
+
java.lang.RuntimeException: Unable to stop activity {com.BSCreate.cpubatteryindicatorinstatusbar/com.Create12c.cpubatteryindicatorinstatusbar.MainActivity}: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.Create12x.cpubatteryindicatorinstatusbar.SetNotification)
|
58
58
|
at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5410)
|
59
59
|
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:5345)
|
60
60
|
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:5455)
|