Performing stop of activity that is not resumed

举报
风吹稻花香 发表于 2021/06/05 01:19:56 2021/06/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. Coincident...

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.


  
  1. public void showSettingsAlert(Context context){
  2. AlertDialog.Builder alertdialog = new AlertDialog.Builder(context);
  3. alertdialog.setTitle("Oups ! pas de données GPS");
  4. alertdialog.setMessage("GPS n'est pas activé sur votre appareil, voulez vous l'activer ?");
  5. /*
  6. handling the buttons :
  7. */
  8. alertdialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
  9. public void onClick(DialogInterface dialog,int which) {
  10. Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  11. startActivityForResult(intent, RESULT_CODE_GPS);
  12. }
  13. });
  14. // on pressing cancel button
  15. alertdialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  16. public void onClick(DialogInterface dialog, int which) {
  17. dialog.cancel();
  18. }
  19. });
  20. alertdialog.show();
  21. }

参考: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

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/66586898

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。