When you make an app, you need to set a passwordYo
So I just made the password entry window
The problem is that the password window pops up every time we move on to the activity (Even when I go out to the home screen, I have to set the password, so I have to check the password on Resume.) I think it'll work)
So I'm going to put a flag here (
)))For example, if there is activity A and B, now it is
From onStop of A to isPasswd = true and from OnCreate of activity of B to isPasswd = false
And I'm checking the password on B's on Resume
So if you move from A to B in the activity,
B's onCreate -> onResume -> A's onStop is called in the order of the action you want, but
If onResume occurs in exceptional situations, you have to check everything
It's a little hard to say, but I don't think it's good to implement the password setting function like this.
I'd like to inquire Thank you always ^
^ android
I'm leaving an answer, not a comment, to explain it with the code.
The logic you are trying to implement can be implemented in the following way.
The Activity that creates and creates the Custom Activity Class will inherit the Custom Activity.
Also, when creating the first activity in onResume()
, skip the password input screen.
The actions of First, create a parent activity class that performs the desired action as shown below. The activity you create inherits MySecurityActivity, not AppCompatActivity. This implementation will reduce repetitive code writing. I hope it helps.onStop()
and onResume()
are repeated, so only the corresponding method is override in parent activitypublic class MySecurityActivity extends AppCompatActivity {
boolean isFirstShow = true;
@Override
protected void onResume() {
super.onResume();
if(isFirstShow) {
showPasswordView();
}
isFirstShow = false;
}
@Override
protected void onStop() {
super.onStop();
// // doIt your code
}
}
public class DataListActivity extends MySecurityActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// // doIt your code
}
}
As you said, if you have a lot of activity, you have to deal with all possible exceptions. Of course, there may not be many cases to deal with. And there's something that's reluctant to check with boolean. You can also use the parent Activity with the relevant exception processed by extending that activity.
In this case, there is a way to implement Service
to import running task
and check that the app has been uploaded to the top task, and then process it to display the password screen. However, I understand that getRunningTask()
is currently deprecated
. An alternative API is getRunningAppProcesses()
. Even if you don't know the name of the activity, you can check it through the package name.
I read the question a few times, but I don't understand what you mean. Typically, passwords are entered once at first and then given permission to work. Does the app you make have a different password for each activity?
For a typical flow, create a data class as shown below.
public class UserInfo {
public static boolean isUnlockPassword;
}
When entering a password, modify the static variable according to the result.
if(strPassword.compareTo(strUserInput))
UserInfo.isUnlockPassword = true;
else
UserInfo.isUnlockPassword = false;
There is a way to use this variable as a flag to determine if the user succeeded in unpacking the password.
if(UserInfo.isUnlockPassword) {
doIt();
} } else {
showPasswordView();
}
© 2024 OneMinuteCode. All rights reserved.