启动设置为活动结果 [英] Starting Settings Activity for result
本文介绍了启动设置为活动结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的申请,我检查GPS是否是用户的设备上启用,如果没有,我想送他到设置让他打开它。
In my application I'm checking whether the GPS is enabled on the user's device, and if not I would like to send him to the Settings to let him turn it on.
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, LocationHelper.LOCATION_SETTINGS_REQUEST_CODE);
在用户关闭设置界面后,我就到右内执行操作的的onActivityResult()
。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == LocationHelper.LOCATION_SETTINGS_REQUEST_CODE) {
LogUtils.d("onActivityResult from settings");
fetchCurrentLocation();
}
}
但是,的onActivityResult()
不会被调用。难道我做错了什么,或这种做法不一般的工作吗?先谢谢了。
However, the onActivityResult()
doesn't get called. Am I doing something wrong or this approach doesn't work in general? Thanks in advance.
推荐答案
劳克设置意图:
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
和在onResume方法获取当前的位置:
and fetch the current location in onResume method :
public void onResume(){
super.onResume();
if(isGPSEnabled){
fetchCurrentLocation();
}
}
从设定画面支持后,你的onResume方法将被调用,在这里你可以获取你的位置。
after backing from setting screen , your onResume method will be call and here you can fetch your location.
这篇关于启动设置为活动结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文