In my project, I have to lock the orientation of an activity. (I cannot recreate the activity)
I want to display a message when the user change the orientation of th
Below code is working for me.
MainActivity.java:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService( new Intent(this, Receiver.class) );
}
}
BackgroundService.java
public class Receiver extends Service {
private static final String BCAST_CONFIGCHANGED = "android.intent.action.CONFIGURATION_CHANGED";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
IntentFilter filter = new IntentFilter();
filter.addAction(BCAST_CONFIGCHANGED);
this.registerReceiver(mBroadcastReceiver, filter);
}
@Override
public void onDestroy() {
}
@Override
public void onStart(Intent intent, int startid) {
}
public BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent myIntent) {
if ( myIntent.getAction().equals( BCAST_CONFIGCHANGED ) ) {
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
}
else {
}
}
}
};
}
Manifestfile.xml