我是android编程的初学者。我不清楚共享偏好的概念。 我需要在应用程序的第一次启动(来自片段活动的片段)和连续启动应用程序(最小化)另一个动画时设置特定的动画。那么如何利用共享偏好呢?
答案 0 :(得分:3)
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
}
}
答案 1 :(得分:0)
点击this
上的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://viralpatel.net/blogs/android-preferences-activity-example/
答案 2 :(得分:0)
对于动画,请使用此
overridePendingTransition(R.anim.no_anim, R.anim.slide_to_top);
创建动画在“res”中创建“anim”文件夹并创建如下所示的slide_left.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>