我在我的應用程序創建偏好活動,讓用戶啓動/停止背景閃屏音樂如下:替代addPreferencesFromResource其棄用
public class Prefs extends PreferenceActivity{
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}
和XML文件夾中創建的prefs.xml:
<?xml version="1.0" encoding="utf-8" ?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="splash music"
android:defaultValue="true"
android:key="checkbox"
android:summary="Plese remove music "/>
</PreferenceScreen>
和驗證碼飛濺的活動:
public class Splash extends Activity{
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle Drandroid) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// TODO Auto-generated method stub
super.onCreate(Drandroid);
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(5000); }
catch (InterruptedException e){
e.printStackTrace(); }
finally{
Intent openTurkeyTrip = new Intent("com.android.dr.MENU");
startActivity(openplanet); }}
};
timer.start(); }
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
我怎麼能與其他CLAS解決問題S的不會被棄用也是我的應用程序將支持新老設備如下:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
任何意見可以理解,謝謝。
的可能重複[在一個PreferenceActivity而是使用「addPreferencesFromResource」怎麼樣?](http://stackoverflow.com/問題/ 682231 9/what-to-use-instead-of-addpreferences fromresource-in-a-preferenceactivity) – Mafro34 2013-11-27 12:23:44
duplicate問題 – 2016-02-15 11:33:16