Reputation: 764
In my application my activity automatically gets close when I come back from background and it always shows previous activity. Example: I start app with Activity A > then goes to activity B> then activity C now I put my app in background and come and then I comeback to foreground the C activity automatically gets close it shows activity B. please help me its a big project I am working on existing code. I don't know what property has been set there. I have checked onPause() and onResume() methods everywhere in the app nothing is there that can close the activity.
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();
}
}
Upvotes: 1
Views: 365
Reputation: 764
I got the culprit in my code, actually in previous implementation they have added noHostory="true" in Manifests.xml for that activity that's why it was closing.
Upvotes: 2