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 设置窗口返回我的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 GPS 设置窗口返回我的活动
				
        
 
            
        - Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
 - 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
 - 用 Swift 实现 UITextFieldDelegate 2022-01-01
 - android 4中的android RadioButton问题 2022-01-01
 - MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
 - 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
 - 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
 - 想使用ViewPager,无法识别android.support.*? 2022-01-01
 - Android viewpager检测滑动超出范围 2022-01-01
 - Android - 拆分 Drawable 2022-01-01
 
				
				
				
				