【发布时间】:2016-08-15 13:19:39
【问题描述】:
我遇到了一个奇怪的问题,当我最小化我的应用程序(按主页按钮)时,我的IntentService 停止了。 IntentService 中有一个 while 循环,它在 IntentService 中运行良好,直到应用程序在前台运行。
IntentService类如下:
public class MainService extends IntentService {
public MainService() {
super("MainService");
}
@Override
protected void onHandleIntent(Intent intent) {
try {
Instrumentation inst = new Instrumentation();
while (true) {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_DOWN);
}
} catch(Exception e){
e.printStackTrace();
}
}
}
并从我的Activity 类中将其称为:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void mainButtonClick(View view) {
Intent intentX = new Intent(this, MainService.class);
this.startService(intentX);
}
}
【问题讨论】:
标签: android intentservice android-intentservice