Run Android app twice to work, why?

I am making an Android app that checks if certain security features are enabled on your phone. For example, if you have enabled a password, or your data is encrypted on your phone.

For some reason, the application needs to run twice to check and check if these security features are enabled on the phone or not, and this is the problem I'm trying to solve. I would like it to test and see if security features are enabled when creating the application and when you first launch the application, and not the second time.

I am testing whether these functions are included in the onStart() function in my MainActivity file. I have included the function code below:

  @Override @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @SuppressLint("NewApi") public void onStart() { super.onStart(); //determine if phone uses lock pattern //It returns 1 if pattern lock enabled and 0 if pin/password password enabled ContentResolver cr = getBaseContext().getContentResolver(); lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED, 0);//Settings.System //returns 1 if pin/password protected. 0 if not KeyguardManager keyguardManager = (KeyguardManager) getBaseContext().getSystemService(Context.KEYGUARD_SERVICE); if( keyguardManager.isKeyguardSecure()) { //it is pin or password protected pinPasswordEnable=1; } else { //it is not pin or password protected pinPasswordEnable=0; }//http://stackoverflow.com/questions/6588969/device-password-in-android-is-existing-or-not/18716253#18716253 //determine if adb is enabled. works adb=Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0); //determine if bluetooth is enabled.works bluetooth=Settings.Global.getInt(cr, Settings.Global.BLUETOOTH_ON, 0); //Settings.System BLUETOOTH_DISCOVERABILITY //determine if wifi is enabled. works WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE); if (wifi.isWifiEnabled()) { //wifi is enabled wifiInt=1; } else wifiInt=0; //determine if data is encrypted getDeviceEncryptionencryption(); //determine if gps enabled }//end of onStart() function 

If any other code needs to be sent to answer this question, just let me know and thanks for your help. Perhaps the problem is related to super.onStart();

Does anyone think a pop-up screen can help solve the problem?

+5
source share
1 answer

super.onStart (); It's good. The screensaver will not help.

From your code, I don’t see how you determine how many times it was executed. Do you also mention testing - is it manual testing or are you using any kind of framework? Perhaps your framework has some init method that runs before each run, and it makes this extra call to onStart ().

There are no problems in this code. Use a debugger or logcat and find out who calls you twice and how @nasch asked what happens on first launch.

However, the real question that will help you remains - what do you mean by “double call”. This is whether you manually click on the application icon twice, or is it some kind of test infrastructure that calls your application twice. Both cases are clear to solve.

+1
source

All Articles