質問編集履歴
1
コード追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1 +1,171 @@
|
|
1
1
|
runしたあとの30~40秒の間foregroundのserviceからホームボタンを押したときにIntentServiceを使用できなくなっています。仕様ですか?
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
#コード1service
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
@Override
|
10
|
+
|
11
|
+
public void onCreate() {
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
super.onCreate();
|
16
|
+
|
17
|
+
final SharedPreferences sn=getSharedPreferences("today",MODE_MULTI_PROCESS);
|
18
|
+
|
19
|
+
final SharedPreferences.Editor editor=sn.edit();
|
20
|
+
|
21
|
+
editor.putInt("start",1).commit();
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
m_HomeButtonReceive = new HomeButtonReceive();
|
26
|
+
|
27
|
+
IntentFilter iFilter = new IntentFilter();
|
28
|
+
|
29
|
+
iFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
30
|
+
|
31
|
+
this.registerReceiver(m_HomeButtonReceive, iFilter);
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
public int onStartCommand(Intent intent, int flags, int startId) {
|
46
|
+
|
47
|
+
Notification notification=new NotificationCompat.Builder(this)
|
48
|
+
|
49
|
+
.setSmallIcon(R.drawable.icon)
|
50
|
+
|
51
|
+
.setContentText("×××" )
|
52
|
+
|
53
|
+
.setContentTitle("×××").build();
|
54
|
+
|
55
|
+
NotificationManager manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
56
|
+
|
57
|
+
manager.notify(1,notification);
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
startForeground(1,notification);
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
return START_STICKY;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
@Override
|
80
|
+
|
81
|
+
public IBinder onBind(Intent intent) {
|
82
|
+
|
83
|
+
return null;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
public class HomeButtonReceive extends BroadcastReceiver {
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
@Override
|
96
|
+
|
97
|
+
public void onReceive(Context arg0, Intent arg1) {
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
Bundle bundle = (arg1 == null) ? null : arg1.getExtras();
|
102
|
+
|
103
|
+
Object o = (bundle == null) ? null : bundle.get("reason");
|
104
|
+
|
105
|
+
Toast.makeText(arg0.getApplicationContext(),(String)o,Toast.LENGTH_LONG).show();
|
106
|
+
|
107
|
+
if (((String)o).equals("homekey")) {//o instanceof String &&
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if (sn.getInt("×××", 0) != 1)
|
112
|
+
|
113
|
+
startService(new Intent(getApplicationContext(), APPintentservice.class));
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
#コード2 intentservice
|
128
|
+
|
129
|
+
public class APPintentservice extends IntentService {
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
public APPintentservice(String name) {
|
134
|
+
|
135
|
+
super(name);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
public APPintentservice() {
|
142
|
+
|
143
|
+
super("APPintentservice");
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
@Override
|
152
|
+
|
153
|
+
protected void onHandleIntent(Intent data) {
|
154
|
+
|
155
|
+
SystemClock.sleep(100);
|
156
|
+
|
157
|
+
Intent intent = new Intent();
|
158
|
+
|
159
|
+
intent.setAction("×××");
|
160
|
+
|
161
|
+
sendBroadcast(intent);
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
自分のコードから抜粋してきたので抜けがあるかもしてません
|