同樣的啟動後也必須要使用stopService()關閉。
在這邊需要注意的有幾點
1) startService()
2) stopService()
3) AndroidManiFest.xml增加service權限
第一點為開啟service必要條件,當然你要new一個intent
所以就是:
Intent intent = new Intent(MainActivity.this,service_class.class); startService(intent);
MainActivity為你目前的class,service_class則是另外開的java檔(那邊則是寫service做的事情)
Intent intent = new Intent(MainActivity.this,service_class.class);
stopService(intent);
第三點就是你需要在Android ManiFest.xml裡面新增權限 <service android:name="service_class"></service>
沒有留言:
張貼留言