java - media player still plays in all activities when device is rotated even though locked to portrait -


this first time dealing media player, have sound play when app starts problem having sound played again when device rotated though locked portrait, happening in fragments when rotated , want sound play when app starts , not again! have tried adding..

android:configchanges="orientation|keyboard|keyboardhidden|screensize"

to manifest in mainactivity advised not working , seems odd me!

here main activity java code media player set up.

public class mainactivity extends appcompatactivity {        toolbar toolbar;      tablayout tablayout;      viewpager viewpager;      viewpageradapter viewpageradapter;        @override      protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);          setcontentview(r.layout.activity_main);        toolbar = (toolbar)findviewbyid(r.id.toolbar);          setsupportactionbar(toolbar);            tablayout = (tablayout)findviewbyid(r.id.tablayout);          viewpager = (viewpager)findviewbyid(r.id.viewpager);          viewpageradapter = new viewpageradapter(getsupportfragmentmanager());          viewpageradapter.addfragments(new homefragment(),"welcome");          viewpageradapter.addfragments(new topthreefragment(),"main display");          viewpageradapter.addfragments(new toppaidfragment(),"options");          viewpageradapter.addfragments(new forthtestfragment(),"news");          viewpageradapter.addfragments(new about(),"about");            viewpager.setadapter(viewpageradapter);          tablayout.setupwithviewpager(viewpager);            final mediaplayer mp = mediaplayer.create(this, r.raw.firsteps);          mp.start();        }    }

replace 1

android:configchanges="orientation|keyboard|keyboardhidden|screensize"

to

android:configchanges="orientation|screensize" one.

and make double check adding related activtiy.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -