[英]How do I know whether or not my Android app is running in background?
There is a WebView in my Android App. 我的Android应用程序中有一个WebView。
I make a toast to show the loading progress. 我举杯祝酒,以显示加载进度。
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
super.onProgressChanged(view, progress);
toast.setText("Loading..." + String.valueOf(progress) + "%");
toast.show();
}
});
The problem is that when I press "home" button or start another Activity, it still keep updating and showing the toast. 问题是,当我按下“主页”按钮或启动另一个活动时,它仍然会不断更新并显示吐司。
Is there way to check if the current Activity is showing? 有没有办法检查当前活动是否显示?
For instance: 例如:
if(getActivity().isVisible())
toast.show();
You could set yourself a boolean flag in onStop() which gets called as you are being removed from the screen. 您可以在onStop()中设置一个布尔标志,当您从屏幕上移除时,它会被调用。
private boolean amShowing = false;
protected void onStart(){
super.onStart();
amShowing = true;
}
protected void onStop() {
super.onStop();
amShowing = false;
}
when with your if statment you can use 何时使用你的if语句你可以使用
if(amShowing) {
toast.show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.