0

내 응용 프로그램 내에서 암호 화면을 구현했지만 활동 A 또는 활동 B가 표시되어야하는지 여부를 확인하기 위해 점검을 수행해야하며이 확인은 공유 환경 설정의 결과임이 분명합니다. , 응용 프로그램을 열 때 눈에 띄는 지연이 있습니다 - 코드는 아래에서 볼 수 있지만 지연없이 빠르고 열 수 있도록이 코드를 어떻게 최적화 할 수 있습니까?Android 스레드에서 UI 스레드의 공유 환경 설정로드

실행기 활동

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    boolean loggedIn = PreferenceUtils.getBoolean(LauncherActivity.this, PreferenceUtils.LOGGED_IN_STATE); 
    boolean passwordEnabled = PreferenceUtils.getBoolean(LauncherActivity.this, PreferenceUtils.APPLICATION_PASSWORD_ENABLED); 

    Log.d(TAG, "LOGGED IN: " + loggedIn + " " + "PW: " + passwordEnabled); 
    if (!loggedIn) { 
     // Start Login Activity 
     Intent intent = new Intent(LauncherActivity.this, ApplicationIntro.class); 
     startActivity(intent); 

     //PreferenceUtils.clearPreferences(LauncherActivity.this); 
    } else { 
     if (passwordEnabled) { 
      // Start Password Activity 
      Intent intent = new Intent(LauncherActivity.this, PasswordActivity.class); 
      startActivity(intent); 
     } else { 
      // Start Main Activity 
      Intent intent = new Intent(LauncherActivity.this, MainActivity.class); 
      startActivity(intent); 
     } 
    } 

    finish(); 
} 

암호 활동

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_password); 

    setupActionBar(); 

    setupPreferences(); 
    findViews(); 
    setupValues(); 
    setListeners(); 

} 

... 

private void setupPreferences() { 
    attemptsRemaining = PreferenceUtils.getInt(PasswordActivity.this, PreferenceUtils.APPLICATION_PASSWORD_ATTEMPTS); 
    storedPassword = PreferenceUtils.getString(PasswordActivity.this, PreferenceUtils.APPLICATION_PASSWORD); 
    duressPassword = PreferenceUtils.getString(PasswordActivity.this, PreferenceUtils.DURESS_PASSWORD); 
} 

성향의 Utils

public static void saveString(Context context, String key, String value) { 
    SharedPreferences preferences = new SecurePreferences(context); 
    SharedPreferences.Editor editor = preferences.edit(); 
    editor.putString(key, value); 
    editor.apply(); 
} 

public static String getString(Context context, String key) { 
    SharedPreferences preferences = new SecurePreferences(context); 
    return preferences.getString(key, ""); 
} 

public static void saveBoolean(Context context, String key, boolean value) { 
    SharedPreferences preferences = new SecurePreferences(context); 
    SharedPreferences.Editor editor = preferences.edit(); 
    editor.putBoolean(key, value); 
    editor.apply(); 
} 

public static boolean getBoolean(Context context, String key) { 
    SharedPreferences preferences = new SecurePreferences(context); 
    return preferences.getBoolean(key, false); 
} 

답변

1

T 그는 Check가 UI Thread를 막고 있기 때문에 App이 지연됩니다. 그것의 좋은 연습 배경 스레드 스레드에서 AsyncTaskhere is a link to AsyncTask documentation을 사용하여 lagy 프로세스를 수행합니다. 추가 문의 사항은 언제든지 물어보십시오.

+0

답장을 보내 주셔서 감사합니다. 이 방법을 제안하는 방법에 대한 몇 가지 코드를 제공 할 수 있습니까? 이전에 AsyncTask를 사용하여이 값을로드하는 동안 패스워드 활동에서 사용자는 실제로 onPostExecute의 결과로 업데이트되는 컨텐츠를 볼 수 있습니다. 그러므로 당신이 이것을 권고하는 방법에 대한 몇 가지 코드를 제안 할 수 있다면, 그것은 좋을 것입니다 - 고마워요. 또한 Launcher 활동의 onCreate는보기가없는 유일한 파일이며 PasswordActivity에는보기가 있습니다 (사용자가 암호와 TextView를 입력 할 수있는 EditText) –

+0

app.when 응용 프로그램의 흐름은 무엇입니까? 먼저 어떤 활동을 시작한 다음 시작하십시오! –

+0

실행 프로그램 활동> 공유 환경 설정 인트로 활동 또는 암호 활동 표시 여부 확인> 암호 활동> 공유 환경 설정에서 저장된 암호를 가져 와서 사용자의 입력에 대해 검사합니다. –

관련 문제