0

I am developing a fingerprint sensor application that use good amount of RAM,problem may be related to memory, i tried a lot still unsolved.

Q:- When i press home button application paused and from the recent button it resumed successfully, but when i press power button then unlock my device,it show ANR instead of my application screen.

It means it is not being resumed when unlocking the device.

Please suggest or give solutions if you got my point.

NOTE: Used device is dedicated to my application no other application will be installed or run.

IshRoid
  • 3,696
  • 2
  • 26
  • 39

1 Answers1

0

Maybe you need broadcast receiver to listen screen on or off.

public class ScreenReceiver extends BroadcastReceiver {

    // thanks Jason
    public static boolean wasScreenOn = true;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            // do whatever you need to do here
            wasScreenOn = false;
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            // and do whatever you need to do here
            wasScreenOn = true;
        }
    }

}

And in your Activity, it will be like this

public class ExampleActivity extends Activity {

   @Override
    protected void onCreate() {
        // initialize receiver
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        BroadcastReceiver mReceiver = new ScreenReceiver();
        registerReceiver(mReceiver, filter);
        // your code
    }

    @Override
    protected void onPause() {
        // when the screen is about to turn off
        if (ScreenReceiver.wasScreenOn) {
            // this is the case when onPause() is called by the system due to a screen state change
            System.out.println("SCREEN TURNED OFF");
        } else {
            // this is when onPause() is called when the screen state has not changed
        }
        super.onPause();
    }

    @Override
    protected void onResume() {
        // only when screen turns on
        if (!ScreenReceiver.wasScreenOn) {
            // this is when onResume() is called due to a screen state change
            System.out.println("SCREEN TURNED ON");
        } else {
            // this is when onResume() is called when the screen state has not changed
        }
        super.onResume();
    }

}
Randyka Yudhistira
  • 3,612
  • 1
  • 26
  • 41
  • This solution doesn't work, i tried but still same problem ANR – IshRoid Feb 26 '15 at 06:31
  • 1
    *"An ANR happens when some long operation takes place in the "main" thread. This is the event loop thread, and if it is busy, Android cannot process any further GUI events in the application, and thus throws up an ANR dialog."* show some of your code then – Randyka Yudhistira Feb 26 '15 at 06:34