and*_*qq6 5 java android splash-screen sharedpreferences
我的应用程序从带有音乐的初始屏幕开始,我使用了sharedpreference来停止音乐,因此下次您打开仍没有音乐的应用程序初始屏幕时。
即时通讯试图获得具有三个独立的不同复选框功能的首选项屏幕,并且如果您选中一个复选框,则无法选中另外两个,如下所示:
第一个复选框: 启动带有启动屏幕和音乐的应用程序(通过以下代码实现),
第二个复选框:启动时没有启动屏幕且没有音乐的应用(通过以下代码实现),
第三个复选框: 启动没有启动屏幕和音乐的应用程序(未实现)。
任何帮助将不胜感激,谢谢
代码 :
飞溅:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
偏好:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我达到了我所寻求的一半解决方案,这是三个不同的功能复选框,如下面的代码,但我仍然无法让它们独立检查。
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);
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean without_splash_screen = getPrefs.getBoolean("without_splash_screen", true);
if (without_splash_screen == true)
{
Intent intent = new Intent(Splash.this, MainActivity.class);
startActivity(intent);
}
boolean splash = getPrefs.getBoolean("splash", true);
if(splash == true) {
setContentView(R.layout.splash);
Thread timer = new Thread()
{
public void run()
{
try
{
sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent intent = new Intent(Splash.this, MainActivity.class);
startActivity(intent);
}
}
};
timer.start();
}
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
SharedPreferences getPrefs1 = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean music = getPrefs1.getBoolean("splash_music", true);
if (music == true)
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(2000); }
catch (InterruptedException e){
e.printStackTrace(); }
finally{
Intent intent = new Intent(Splash.this, MainActivity.class);
startActivity(intent); }}
};
timer.start(); }
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1807 次 |
| 最近记录: |