开发者

passcode on application is resumed

开发者 https://www.devze.com 2023-04-01 10:58 出处:网络
how to distinguish wh开发者_如何学编程en app is minimized or a new activity starts? i wanna implement a passcode like in dropbox app, wherein when the app is minimized it will ask for passcode if the

how to distinguish wh开发者_如何学编程en app is minimized or a new activity starts?

i wanna implement a passcode like in dropbox app, wherein when the app is minimized it will ask for passcode if the app resumed. this is what i have in mind.

public static Boolean isMinimized = false;
@Override
public void onResume() {
      super.onResume();
      if(isMinimized)
      {
          isMinimized = false;
          startActivity(new Intent(this, Login.class));
      }
}

@Override
public void onPause() {
      super.onPause();
      isMinimized = true;
      Toast.makeText(this, "Application Minimized", Toast.LENGTH_LONG).show();
}

when i run a new activity i set the isMinimized to false so the login wont popup, however when i minimized it, and return to it, onPause is always triggered since it again paused.

by using getParent() how can i dynamically change static variables.

NOTE: i cannot use casting since its not static who calls this activity

i change the value of isMinimized using im 100% sure the SystemPreferences is the parent.

SystemPreferences.isMinimized = false;

however, is there a way to cast getParent() so i can using something like

((SystemPreferences) getParent()).isMinimized = false;

take note: the parent is dynamic.


Every activity is running through a specific method when moving to the background, resuming etc.

So, if you're in your onResume() method of the activity you know, that this activity just went back to active and is on top. (According to the Android activity cycles: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle)

EDIT: If I understood you correctly, you can "save" the variables you set by saving it as a preference for example.

0

精彩评论

暂无评论...
验证码 换一张
取 消