我想讓關閉程序後service依然執行,但是關了就沒反應了 貼出代碼
public class MainActivity extends ActionBarActivity {
private NotificationManager notificationManager;
private Intent intent;
private Calendar calendar = Calendar.getInstance();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
intent = new Intent("com.example.alarm.MusicService");
Startser();
}
public void Startser()
{
MainActivity.this.startService(intent);
}
@Override
public void onDestroy(){
super.onDestroy();
if(intent != null){
}
}
}
程序是在後台運行的,而不是關閉的,如果關閉了,也就停止運行了;其實程序是在後台運行,而不是指關閉了程序;