clearTaskOnLaunch
을 사용하는 대신 보유한 모든 활동의 'onStart'에 조건문을 넣을 수 있습니다.
예 :
모든 활동에 배치 코드가 더 휴대용 쉽게하기 위해
if (pref.getBoolean("requiresPassword", false)){
startActivity(new Intent(context, SplashScreen.class));
}
, 나는 여러 가지 방법을 포함하는 하나 개의 단일 클래스를 만들 그래서 예를 들면 :
public class M {
public static void check(final Context context){
//do the shared prefs getting and startActivity from here.
}
}
모든 Activity
에 대해 onStart
에서 M.check(this);
편집 :
Scienceprodigy 마찬가지로 위의 infinte 루프가 발생합니다. 나는 그런 생각을하지 않았다.
public static void requestPassword(final Context context){
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
final Activity activity = (Activity)context;
boolean requestPassword = pref.getBoolean("appLock", false);
// Log.i(tag, String.valueOf(requestPassword));
if (!requestPassword){
return;
}
final EditText myPass2 = new EditText(context);
new AlertDialog.Builder(context)
.setTitle("Enter Password")
.setView(myPass2)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
String secPass = pref.getString("secPassword", "password");
String entPass = myPass2.getText().toString();
if (entPass.equals(secPass)){
myPass2.setText("");
saveTime(context);
} else {
Toast.makeText((Activity)context, "Incorrect Password", Toast.LENGTH_SHORT).show();
myPass2.setText("");
activity.finish();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
myPass2.setText("");
activity.finish();
}
})
.setCancelable(true)
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
myPass2.setText("");
activity.finish();
}
})
.show();
}
이 암호를 입력하는 등 다음 암호 검사를, 암호 검사의 무한 루프를 만듭니다 –
나는를 시작 대신에 AlertDialog를 사용하는 내 대답을 업데이트 @Scienceprodigy 스플래시 화면. 이것은 정확히 원하는 것일 수는 없지만 사용자 입장에서는 다중 작업을 시도 할 때 대화를 선호합니다. 그것은 더 쉬운 것처럼 보인다. 물론 더 잘 맞는 경우 XML로 정의 된 사용자 정의 레이아웃을 사용할 수 있습니다. – Jakar