Performing stop of activity that is not resumed

来源:互联网 发布:归来 知乎 编辑:程序博客网 时间:2024/06/10 20:05

That doesn't seem right to me. The splash activity would now be the top activity in the stack, so the HomeActivity onStop lifecycle method would get called eventually. Coincidentally, I moved the startActivity call for the splash activity from onCreate to onResume in the HomeActivity, and the error goes away.

gps.showSettingsAlert();//inside this use startActivityForResult(new Intent().setClass(this, MainActivity.class), result_code);


Edit: your method should be in MainActivity.class not in Service as service don't have ui so no point of getting the result there.

  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();        }

参考:http://stackoverflow.com/questions/25867085/refreshing-activity-performing-stop-of-activity-that-is-not-resumed-error

http://stackoverflow.com/questions/21947675/android-4-4-2-java-lang-runtimeexception-performing-stop-of-activity-that-is

0 0
原创粉丝点击