My app start by splash screen with music , i used sharedpreference to stop music so next time you open the app splash screen still there without music .
im trying to get preference screen with three independent different checked box functions and also if you check one checkedbox you can not check the other two as below :
First checkedbox: start app with splash screen and music ( achieved by below code ) ,
Second checkedbox: start app with splash screen and without music ( achieved by below code ) ,
third checkedbox: start app without splash screen and music ( not achieved ) .
any help will be appreciated , thanks
the code :
Splash :
public class Splash extends Activity{
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences
(getBaseContext());
boolean music = getPrefs.getBoolean("checkbox", true);
if (music == true)
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(1000); }
catch (InterruptedException e){
e.printStackTrace(); }
finally{
Intent openMainActivity = new Intent("com.test.demo.MENU");
startActivity(openMainActivity); }}
};
timer.start(); }
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
Prefs :
public class Prefs extends PreferenceActivity{
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
Boolean customTitleSupported = requestWindowFeature
(Window.FEATURE_CUSTOM_TITLE);
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}
prefs.xml:
<?xml version="1.0" encoding="utf-8" ?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference android:title="splash screen music"
android:defaultValue="true"
android:key="checkbox"
android:summary="remove mark to stop music when splash start" />
</PreferenceScreen>
SharedPreferences getPrefs =PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean music = getPrefs.getBoolean("checkbox");
if (music == true)
{
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
ourSong.start();
Thread timer = new Thread()
{
public void run()
{
try
{
sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent openMainActivity = new Intent("com.test.demo.MENU");
startActivity(openMainActivity);
}
}
};
timer.start();
}
}
else
{
Intent openMainActivity = new Intent("com.test.demo.MENU");
startActivity(openMainActivity);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With