Android - 为什么在 Android OS 11 上屏幕解锁后,在 Activity 上声明的所有变量、视图在 onRestart() 方法中都变为 null?
我正在尝试开发一个应用程序,但我遇到了下面提到的情况:
1。我正在我的应用程序的活动中。
2.我的屏幕在 5 分钟后关闭(锁定)
3。我解锁手机
4。解锁后,Activity 上的 onRestart() 方法被调用,我已经在 onRestart() 方法上完成了一些代码
5。但是,当我调试应用程序时,onRestart() 上的所有变量和视图都变为 null
我在 onRestart() 方法中的代码。
@Override
protected void onRestart() {
super.onRestart();
try {
if (new CommonUtils()
.isConnectingToInternet(getApplicationContext()))
new UpdatetoServerAsynk(getApplicationContext()).execute();
GlobalData globalData = (GlobalData) getApplicationContext();
CommonDomain serverLogin = globalData.getServercredentials();
if (serverLogin == null || !serverLogin.Date.equals(new CommonUtils().getCurrentDate())) {
new CommonUtils().forceLogout(this);
}
if (globalData.getUserdetails().TimeInOutFlag == GlobalData.PUNCHED_IN)
mUsernameTextView.setTextColor(Color.parseColor(GlobalData.GREEN));
else
mUsernameTextView.setTextColor(mColorStateList);
new myAsync(HomescreenActivity.this).execute();
} catch (Exception e) {
e.printStackTrace();
}
}
所有数据甚至视图都显示为空。我不知道为什么一切都归零了。并且仅在 Android 11 操作系统中使用。我的目标&编译的SDK是31。我检查了是否是由于内存不足而发生的,没有。有人在开发时遇到这种问题吗?如果有的话,有什么解决方案或知道为什么会发生这种情况吗?
I am trying to develop a application but I got stuck in a case that I mentioned below :
1. I am in an Activity of my application.
2. My screen turned off (locked) after 5 min
3. I unlock mobile
4. After unlock, onRestart() method on Activity called and I have done some code on onRestart() method
5. But all variable and views on onRestart() is getting null when I debugged the app
My code in onRestart() method.
@Override
protected void onRestart() {
super.onRestart();
try {
if (new CommonUtils()
.isConnectingToInternet(getApplicationContext()))
new UpdatetoServerAsynk(getApplicationContext()).execute();
GlobalData globalData = (GlobalData) getApplicationContext();
CommonDomain serverLogin = globalData.getServercredentials();
if (serverLogin == null || !serverLogin.Date.equals(new CommonUtils().getCurrentDate())) {
new CommonUtils().forceLogout(this);
}
if (globalData.getUserdetails().TimeInOutFlag == GlobalData.PUNCHED_IN)
mUsernameTextView.setTextColor(Color.parseColor(GlobalData.GREEN));
else
mUsernameTextView.setTextColor(mColorStateList);
new myAsync(HomescreenActivity.this).execute();
} catch (Exception e) {
e.printStackTrace();
}
}
All data is showing null even the views. I don't know why its all went to null. And its getting only in Android 11 OS. My target & Compiled SDK is 31. I checked whether it occur due to low memory and its not. Is anyone have this kind of problem while developing If so any solution or any idea why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论