5

My android app will run at background and I need to be notify immediately when orientation change. eg. When user rotate the phone from portrait to landscape (or landscape to portrait), the system should be tell my app that the orientation has changed.

Thanks.

3 Answers 3

7

This method is called when screen rotated

@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); //Do stuff here } 
Sign up to request clarification or add additional context in comments.

4 Comments

Does this method will be call if my app hasn't been started? What I really need is that my app wake up (or start) when orientation change.
Read this and this
I have read these before I post the question. They said that "Called by the system when the device configuration changes while your activity is running." So, the method will not be call if my app isn't running. Is there any solution for me?
@NguyenMinhBinh Do you solved it? I have the same problem now, thanks.
3

You do not have to explicitly set the Orientation listener.

onConfigurationChanged will be called by the system.

@Override public void onConfigurationChanged(Configuration myConfig) { super.onConfigurationChanged(myConfig); int orient = getResources().getConfiguration().orientation; switch(orient) { case Configuration.ORIENTATION_LANDSCAPE: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Configuration.ORIENTATION_PORTRAIT: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; default: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } 

Comments

0

But you can implement onConfigurationChanged in daemon. here : Service.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.