在我的应用程序中,当我从后台返回时,我的活动会自动关闭,并且它始终显示以前的活动。示例:我使用活动A>启动应用程序然后进入活动B>然后活动C现在我把我的应用程序放在后台然后然后我回到前台C活动自动关闭它显示活动B.请帮我一个大项目我正在处理现有代码。我不知道那里有什么财产。我在应用程序的任何地方都检查了onPause()和onResume()方法,没有什么可以关闭活动。
public class EnterOtpActivity extends ChoosePhotoBaseActivity {
private ActivityEnterOtpBinding mBinding;
private EnterOtpModel model;
private String name;
private String prefix;
private String phone;
private String password;
private int spinnerPos;
private UserApi.FacebookLoginDetails fbLoginDetails = null;
@NonNull
@Override
protected Map<ImageView, Transformation<Bitmap>> getImageViewsMap() {
return null;
}
@Override
protected void handleLoadedFile(@NonNull File imageTempFile) {
imageCropped(Uri.fromFile(imageTempFile));
}
public void imageCropped(@NonNull Uri croppedImageUri) {
model.mEditAvatarUri = croppedImageUri;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_enter_otp);
mBinding.setModel(model = new EnterOtpModel(this, mBinding));
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
if (bundle.containsKey(BundleKeyUtils.REGISTRATION)) {
UserDetailsForOTPVo userDetailsForOTPVo = (UserDetailsForOTPVo) bundle.getSerializable(BundleKeyUtils.REGISTRATION);
name = userDetailsForOTPVo.getName();
prefix = userDetailsForOTPVo.getPrefix();
phone = userDetailsForOTPVo.getContactNumber();
password = userDetailsForOTPVo.getPassword();
spinnerPos = userDetailsForOTPVo.getSpinnerPosition();
model.setContactNumber(prefix, phone);
} else if (bundle.containsKey(BundleKeyUtils.FB_REGISTRATION)) {
fbLoginDetails = (UserApi.FacebookLoginDetails) bundle.getSerializable(BundleKeyUtils.FB_REGISTRATION);
prefix = fbLoginDetails.getPhone_country_code();
phone = fbLoginDetails.getPhone();
}
}
mBinding.editOtp.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4)});
model.setTimer();
setContinueAction();
otpTextWatcher();
setOnOtpRequest();
File f = new File(getApplicationContext().getCacheDir(), "temp");
Uri imageUri = Uri.fromFile(f);
model.mEditAvatarUri = imageUri;
mBinding.textContinue.setEnabled(false);
}
private void setOnOtpRequest() {
mBinding.textOTp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOTPDialog();
}
});
}
private void setContinueAction() {
mBinding.textContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBinding.textContinue.setVisibility(View.INVISIBLE);
mBinding.progressContinue.setVisibility(View.VISIBLE);
mBinding.imgvArrow.setVisibility(View.INVISIBLE);
if (fbLoginDetails == null) {
model.onContinueAction(prefix, phone, password, name, mBinding.editOtp.getText().toString(), spinnerPos);
}else {
//TODO FB web call
fbLoginDetails.setOTP_code(mBinding.editOtp.getText().toString());
model.onFbLoginAction(fbLoginDetails, () -> {
mBinding.textContinue.setVisibility(View.VISIBLE);
mBinding.progressContinue.setVisibility(View.INVISIBLE);});
}
}
});
}
public void otpTextWatcher() {
mBinding.editOtp.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(@NonNull String newText) {
super.onTextChanged(newText);
if (newText.length() == 4) {
mBinding.textContinue.setEnabled(true);
mBinding.textContinue.setBackgroundResource(R.drawable.button_background_selector);
}else {
mBinding.textContinue.setEnabled(false);
mBinding.textContinue.setBackgroundResource(R.drawable.bg_rounded_button_light_orange);
}
}
});
}
public void showOTPDialog() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(EnterOtpActivity.this,
R.style.DialogDark));
String meddleD = getResources().getString(R.string.dialog_msg_sms_middle);
alertDialogBuilder.setMessage(getResources().getString(R.string.dialog_msg_sms_will_be) +" "+ prefix + phone +meddleD+getResources().getString(R.string.dialog_is_this_number_correct));
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setPositiveButton(R.string.fragment_contacts_invite_sms_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
mBinding.textOTp.setVisibility(View.INVISIBLE);
mBinding.progressLogIn.setVisibility(View.VISIBLE);
mBinding.editOtp.setText("");
model.reSendOtpRequest();
}
});
alertDialogBuilder.setNegativeButton(R.string.edit, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
alertDialogBuilder.show();
}
//disable back button
@Override
public void onBackPressed() {
// do nothing
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
}
}
答案 0 :(得分:1)
我在我的代码中遇到了罪魁祸首,实际上在之前的实现中,他们在Manifests.xml中为该活动添加了noHostory =“true”,这就是它关闭的原因。