我希望在启动服务后立即退出应用程序。
以下代码会在启动服务之前结束活动。 如何设置监听器,在服务启动时提示我?
btn = (ImageButton) findViewById(R.id.button );
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startService(new Intent(MainActivity.this, MyService.class));
//I want to exit the activity here.
finish(); // this exits the activity before the service is started
}
});