how to handle screen rotations when app is in background and user is on home screen android -
i have scenario recording in background service. want record videos based on user mode selection.
selection modes : portrait/ landscape-right/landscape-left
lets selected mode landscape-left , app goes in background , user rotated device if happens want record video in landscape-left only;
i have tried following
public void onconfigurationchanged(configuration newconfig) { int orientation = getresources().getconfiguration().orientation; }
but seems dosen't event on home screen. can resolve issue?
thanks in advance
you can use broadcastreceiver background service like:
private final broadcastreceiver mreceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { if (intent != null) { if (intent.action_configuration_changed.equals(intent.getaction())) { //configuration has changed } } } }; @override public void oncreate() { super.oncreate(); registerreceiver(mreceiver, new intentfilter(intent.action_configuration_changed)); } @override public void ondestroy() { super.ondestroy(); unregisterreceiver(mreceiver); }
you can find more information on in documention.
broadcast action: current device configuration (orientation, locale, etc) has changed. when such change happens, uis (view hierarchy) need rebuilt based on new information; part, applications don't need worry this, because system take care of stopping , restarting application make sure sees new changes. system code can not restarted need watch action , handle appropriately.
note intent can retrive registerreceiver, not manifest via intent filter
Comments
Post a Comment