android - Android 活动生命周期处理错误
问题描述
美好的一天,所以我有这个程序,用户将在其中扫描 QR 码并在 SQLite 数据库中获取它的值,但在我得到值之前,对话框弹出消息告诉我“没有找到参与者”。下面是我的代码:
这是我的 onStart 覆盖。
@Override
protected void onStart()
{
super.onStart();
getparticipantid = tvParticipantID.getText().toString();
etparticipantidvalue.setText(getparticipantid);
getParticipantIbeam();
}
这是我的活动,一旦用户扫描二维码,它将从数据库中加载数据。
private void getParticipantIbeam()
{
SQLiteFunctionUlitity.GameIBeamParticipant memberInfo = SQLiteFunctionUlitity.getparticipantIbeam(getparticipantid, mDbHelper.getSqliteObjectWithReadable());
if (memberInfo != null)
{
tvParticipantName.setText(memberInfo.getParticipantName());
tvParticipantNation.setText(memberInfo.getParticipant_nationality());
tvParticipantCategory.setText(memberInfo.getCategory());
tvWave.setText(memberInfo.getWave_number());
tvCategory.setText(memberInfo.getCategory());
}
else
{
Context context = this;
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setMessage("No Participant found in the Game.");
builder1.setCancelable(true);
builder1.setPositiveButton("Scan Again", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
Intent intent = new Intent(GameiBeamLineTracing.this, ScanGameIbeam.class);
startActivity(intent);
finish();
}
});
builder1.setNegativeButton("Close", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
onStop();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
}
如您所见,我在 onStart 方法中调用 getParticipantIbeam 活动,但是当我调用它时,它读取的是 else 语句而不是 if 语句。
我知道这是一个简单的 if else 语句和生命周期,但我很想知道答案。
解决方案
推荐阅读
- python - 为 Python 3.8、Windows 安装 PySide2
- r - 将 data.frame 转换为具有数字和字符数据特定排序的行?
- angularjs - AngularJs ng-repeat 在范围更改后不排序时间列表
- mysql - Docker Compose:将 WordPress 容器连接到 MySQL 容器?
- firebase - how to handle firebase auth exceptions in flutter?
- reactjs - use create-react-app and don't have any folder
- quantum-computing - How to pass one Q# operation to another Q# operation from C# or F#
- php - 管理雇主的 SQL 请求或 php 解决方案
- seo - hreflang 中国台湾 zh-Hans zh-Hant 或 zh-cn zh-tw
- html - flex + min-height = 0 高度的孙子