How can I return back to my Activity from GPS settings window(如何从 GPS 设置窗口返回我的活动)
问题描述
我的 Activity 出现问题,它可以控制 android 移动 GPS 设置以让用户打开/关闭 GPS,但我无法返回我的 Activity.当我按下后退按钮时,它会直接进入手机的主页,而不是从我向设置发送信号的地方返回我的活动.谁能告诉我解决办法.
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;
}
}
}
推荐答案
适合我.您确定您的清单中设置了 ACCESS_FINE_LOCATION 权限吗?你确定正在调用 startActivityForResult() 吗?
Works for me. Are you sure you have ACCESS_FINE_LOCATION permission set in your manifest? Are you sure startActivityForResult() is being called?
另外,什么是 GPS_LOC?
Also, what is GPS_LOC?
这是我的有效代码:
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;
}
}
}
}
这篇关于如何从 GPS 设置窗口返回我的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!