Android application doesn#39;t close after calling System.exit(0)(调用 System.exit(0) 后 Android 应用程序未关闭)
问题描述
I have an Android app that worked great, before I've added admob activity. I'm closing my app with killing process (calling System.exit(0)). I know that this is the worst solution of finishing the app. I'm working with OpenGL states and libgdx framefork, so I can't fixed all memory leak that appear when I'm calling standard android finish() function.
So here's the problem:
My app works normally several times. I close and start it again and again. All works fine, but suddenly admob view doesn't appear and when I'm trying to close, it freezes. The sound works, last screen shows itself, but touching not working.
When I'm killing the process by task manager, the music still playing. Even when I completely remove the app, music still playing, so activity still working. It stops only when I reboot my phone.
Without admob all works fine. I also trying destroy adView before closing, without result.
Here is my main activity:
public class ControllerActivity extends AndroidApplication{
private AdView adView;
RelativeLayout layout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = true;
cfg.useCompass = false;
cfg.useAccelerometer = false;
layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(Controller.getInstance(), cfg);
adView = new AdView(this, AdSize.BANNER, "MYID");
AdRequest adRequest=new AdRequest();
adView.loadAd(adRequest);
layout.addView(gameView);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(adView, adParams);
setContentView(layout);
}
@Override
public void onDestroy() {
if (adView!=null) {
adView.stopLoading();
adView.destroy();
}
System.exit(0);
super.onDestroy();
}
}
Have your any ideas, how to completely kill this process?
I have found out some facts. If the application is terminated by System.exit(0)
or by android.os.Process.killProcess
the next time AdMob won't show ads. Even more if you try to terminate application it will stuck (the process remain active and the only option to kill it is the device reboot). The only solution is not to use System.exit(0)
to exit application. It should be mentioned that it does not matter whether adView.destroy()
or adView.stopLoading()
was called.
I used this.moveTaskToBack(true);
instead of termination. It will hide the application and if in some time it won't get restored Android will release all resources and AdMob will work OK. If the application will be restored it will continue from the same place.
这篇关于调用 System.exit(0) 后 Android 应用程序未关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:调用 System.exit(0) 后 Android 应用程序未关闭
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01