I know that want to startService is need to call startService() by
Activity.

But my project's purpose is obtain the user's locaiton to determine
where is user place.

And I want that job is work in background. So I use Service

The question is the service didn't stop !?


//this the main Activity to startService and stopService by onClick
button
public void onClick(View v){
        Intent j = new Intent(this,BackGroundService.class);
        switch(v.getId()){
        case R.id.enter_btn:
                startService(j);
                break;
        case R.id.exit_btn:
                stopService(j);
                finish();
                break;
        }


//this is in BackGroundService, to intent a Mapactivity to get
location
@Override
public void onStart(Intent intent, int startId){
        super.onStart(intent, startId);

        intent = new Intent(getBaseContext(), MyLocation.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getApplication().startActivity(intent);
}

@Override
public void onDestroy() {
        super.onDestroy();
        stopSelf();
}

Is my code cause any problem so that led to my Service could't stop?

Or my project shouldn't create this way?



Thank's for reading

-- 
You received this message because you are subscribed to the Google Groups 
"Android Discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/android-discuss?hl=en.

Reply via email to