我是android编程的初学者。我不清楚共享偏好的概念。我需要在应用程序的第一次启动时设置一个特定的动画(来自片段活动的片段),并为应用程序的连续启动设置另一个动画(最小化)。那么,我如何利用共同的偏好来做到这一点呢?
public class MyActivity extends FragmentActivity {
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Perhaps set content view here
prefs = getSharedPreferences("key", MODE_PRIVATE);
}
@Override
protected void onResume() {
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
prefs.edit().putBoolean("firstrun", false).commit();
// here comes your animation for first start
}
// here comes your animation for other starts
}
}
在developer.android.com 上查看此文档
看看这些链接:
http://examples.javacodegeeks.com/android/core/content/android-sharedpreferences-example/
http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html
http://rajeshvijayakumar.blogspot.in/2013/03/shared-preferences-example-in-android.html
http://androiddeveloperspot.blogspot.in/2013/01/sharedpreference-in-android.html
http://alchemiaandroid.altervista.org/sharedPreferencesTutorial.html
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
http://www.edumobile.org/android/android-development/shared-preferences-example-in-android-programming/
http://viralpatel.net/blogs/android-preferences-activity-example/
对于动画,请使用此
overridePendingTransition(R.anim.no_anim, R.anim.slide_to_top);
要创建动画,请在"res"中创建"anim"文件夹,并像下面的一样创建slideleft.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="0%"
android:toXDelta="-100%" />
<alpha
android:duration="200"
android:fromAlpha="1"
android:toAlpha="0" />
</set>