清爽活动/"执行活动的停止未恢复"错误 [英] Refreshing activity / "performing stop of activity that is not resumed" error
问题描述
我想一旦GPS是通过打开的GPS设置的alertdialog启用刷新我的活动。
我实现了onResume功能,但结果我得到这个在我的logcat:
I'm trying to refresh my activity once the GPS is enabled via an alertdialog that opens the GPS settings. I implemented the onResume function but in result I get this on my logcat :
performing stop of activity that is not resumed(...)
我已经看过这个帖子,但我无法弄清楚什么是错了我的code(或我的onResume功能),以及如何从GPS设置回来后刷新我的活动。
I have looked on this post but I can't figure out what is wrong with my code (or my onResume function) and how to refresh my activity after coming back from GPS settings.
你能帮助我吗?
这里是我的 MainActivity.java
推荐答案
致电时您
gps.showSettingsAlert();//inside this use startActivityForResult(new Intent().setClass(this, MainActivity.class), result_code);
编辑:你的方法应该是在MainActivity.class不是Service作为服务没有界面,因此没有得到一点,结果那里
public void showSettingsAlert(Context context){
AlertDialog.Builder alertdialog = new AlertDialog.Builder(context);
alertdialog.setTitle("Oups ! pas de données GPS");
alertdialog.setMessage("GPS n'est pas activé sur votre appareil, voulez vous l'activer ?");
/*
handling the buttons :
*/
alertdialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, RESULT_CODE_GPS);
}
});
// on pressing cancel button
alertdialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertdialog.show();
}
下面是你的活动结果的方法,将用户后,presses从设置页背面被调用。
Here is your Activity result method which will be called after user presses back from Settings page.
@SuppressLint("NewApi") @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == RESULT_CODE_GPS && resultCode == 0){
// @SuppressWarnings("deprecation")
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_MODE);
if(provider != null && !provider.isEmpty()){
Log.v("mAINaBBB", " Location providers: "+provider);
//Start searching for location and update the location text when update available.
// Do whatever you want
}else{
Log.v(, "Nothing put on");
//Users did not switch on the GPS
}
}
}
现在在MainAcitivity自称在那里你之前
Now in the MainAcitivity itself call the method where you called before
if(gps.canGetlocation() ){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
device_location = new ParseGeoPoint(latitude,longitude);
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
showSettingsAlert(MainActivity.this); //**This line should be changed then**
}
这篇关于清爽活动/"执行活动的停止未恢复"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!