Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

android - How can I return back to my Activity from GPS settings window

I am having a problem in my Activity, which can take the control to the android mobile GPS settings to have user to switch on/off the GPS, But I am unable to retrun back to my activity. when I press back button, It is directly going to Home of the mobile, not coming back my Activity from where I send signal to settings. can anyone tell me the solution for this.

if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER )) { 
    startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.e("","OnActivity Result...");
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == GPS_LOC) {
       switch (requestCode) {
          case GPS_LOC:
              //super.onCreate(inst);
              super.onResume();
              //super.finish();
           break;
        }
     }  
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Works for me. Are you sure you have ACCESS_FINE_LOCATION permission set in your manifest? Are you sure startActivityForResult() is being called?

Also, what is GPS_LOC?

Here's my code that works:

public class main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        findViewById(R.id.button1).setOnClickListener( new OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 1) {
           switch (requestCode) {
              case 1:
               break;
            }
         }  
     }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...