立即针对Intent(Settings.ACTION_SETTINGS)调用onActivityResult [英] onActivityResult for Intent(Settings.ACTION_SETTINGS) called immediately
问题描述
在我的启动画面中,我已请求服务器,但是当没有互联网连接时,我正在打开
Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
startActivityForResult(settingsIntent, REQUEST_ENABLE_CONNECTION);
但是问题是onActivityResult
被requestCode = REQUEST_ENABLE_CONNECTION
我也试图为运气添加标志FLAG_NEW_TASK
,但是没有运气.
活动不是manifest
中的不是 singleTop
或singleInstance
.
解决此问题的最佳android解决方案是什么?我不想使用广播,因为它不是通往我的流的最佳方式,因此它将被视为我的最后选择.
非常感谢您的帮助.
如果onActivityForResult
不适用于您(如@CommonsWare建议的那样,可以),您可以创建一个简单的流程,该流程应该可以正常工作:/p>
在您的活动中,添加
private boolean isReturnedFromSettings = false;
当您确定没有互联网连接并想要打开设置活动时,请使用startActivity
并设置isReturnedFromSettings = true;
在活动"的onResume中,添加以下内容:
if (isReturnedFromSettings) {
isReturnedFromSettings = false;
//DO WHATEVER
}
应该工作...
In my splash screen I have request to server, but when there's no internet connection i'm opening
Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
startActivityForResult(settingsIntent, REQUEST_ENABLE_CONNECTION);
But problem is that onActivityResult
is called immediately with requestCode = REQUEST_ENABLE_CONNECTION
I've also tried to add the flag FLAG_NEW_TASK
for the intent with no luck.
The activity is not singleTop
or singleInstance
in the manifest
.
What is the best android solution to resolve this issue? I don't want to use Broadcast as it's not the best way to my flow so it will be taken as last choice for me.
Thanks a lot for the help.
If the onActivityForResult
isn't working well for you (as @CommonsWare suggested, it's fine) you can create a simple flow that should work fine:
In your activity, add
private boolean isReturnedFromSettings = false;
When you decide there's no internet connection and want to open the settings activity, use startActivity
and set isReturnedFromSettings = true;
In your Activity's onResume, add this:
if (isReturnedFromSettings) {
isReturnedFromSettings = false;
//DO WHATEVER
}
Should work...
这篇关于立即针对Intent(Settings.ACTION_SETTINGS)调用onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!