我有這樣的代碼,描述服務:如何停止運行服務?
public class navigation_web extends Service {
Context context;
public void navigation() {
Cursor mCur = getContentResolver().query(Browser.BOOKMARKS_URI,
Browser.HISTORY_PROJECTION, null, null, null);
mCur.moveToFirst();
if (mCur.moveToFirst() && mCur.getCount() > 0) {
while (mCur.isAfterLast() == false) {
Log.v("titleIdx",
mCur.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX));
Log.v("urlIdx",
mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX));
mCur.moveToNext();
}
}
// Browser.clearSearches(getContentResolver());
}
public void onCreate() {
// Browser.clearHistory(getContentResolver());
// Browser.clearSearches(getContentResolver());
navigation();
// super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
我可以用
startService(new Intent(Finalv2Activity.this, navigation_web.class));
調用從活動這一服務,但我想調用它之後停止該運行中的服務,所以我可以稱它爲再次。我怎樣才能做到這一點。謝謝
相關http://stackoverflow.com/questions/5555765/stop-service-in-android – 2016-02-14 10:26:32