运行 仅在第一次启动布局
Run Splash Layout only the First Time
我只想在应用程序首次启动时启动启动画面。我的初始屏幕与另一个屏幕链接,这也是第一次出现。
我的启动画面代码是:
public class SplashPage extends Activity{
private static int startPage = 7000;
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashpage);
prefs = getSharedPreferences("com.tech.spam", MODE_PRIVATE);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
calll();
}
if (prefs.getBoolean("firstrun", false)) {
finish();
startActivity(new Intent(SplashPage.this,MainActivity.class));
}
//prefs.edit().putBoolean("firstrun", false).commit();
//finish();
}
private void calll() {
// TODO Auto-generated method stub
Animation anim = AnimationUtils.loadAnimation(this, R.anim.move);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.startAnimation(anim);
Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.move);
TextView ivvv = (TextView) findViewById(R.id.textView1);
ivvv.startAnimation(anim1);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(SplashPage.this, SplashPageTutorial.class);
startActivity(intent);
overridePendingTransition(R.anim.fade, R.anim.hold);
finish();
}
},
startPage);
}
现在我想做的是,应用程序首次启动时 Splash 运行 7 秒,然后打开下一个屏幕,7 秒后与 splash 链接,然后在第二个屏幕之后我的主屏幕 Activity 开始。
现在我想做的是,当我第一次打开应用程序时,只有 Main Activity 启动(闪屏和与闪屏链接的屏幕现在消失了)
我使用此代码,以便当应用程序再次打开时布尔值 returns false 并启动 Main Activity 但它不会发生
if (prefs.getBoolean("firstrun", true)) {
calll();
}
if (prefs.getBoolean("firstrun", false)) {
finish();
startActivity(new Intent(SplashPage.this,MainActivity.class));
}
//prefs.edit().putBoolean("firstrun", false).commit();
//finish();
请帮忙看看我该怎么办
我的清单是这样的:
<application android:icon="@drawable/appicon"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<activity android:name="com.tech.spam.SplashPage"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.tech.spam.MainActivity"
>
</activity>
<activity
android:name="com.tech.spam.SplashPageTutorial"
android:theme="@style/FullscreenTheme"
>
</activity>
一种简单的方法是共享偏好变量。在启动闪屏时将此变量设置为 true。在启动 activity 之前检查此变量是否为 false 并且仅在它为 false 时启动。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
SharedPreferences settings=getSharedPreferences("prefs",0);
boolean firstRun=settings.getBoolean("firstRun",false);
if(firstRun==false)//if running for first time
//Splash will load for first time
{
SharedPreferences.Editor editor=settings.edit();
editor.putBoolean("firstRun",true);
editor.commit();
Intent i=new Intent(check.this,Splash.class);
startActivity(i);
finish();
}
else
{
Intent a=new Intent(check.this,Main.class);
startActivity(a); // Launch next activity
finish();
}
}
}
我只想在应用程序首次启动时启动启动画面。我的初始屏幕与另一个屏幕链接,这也是第一次出现。 我的启动画面代码是:
public class SplashPage extends Activity{
private static int startPage = 7000;
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashpage);
prefs = getSharedPreferences("com.tech.spam", MODE_PRIVATE);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
calll();
}
if (prefs.getBoolean("firstrun", false)) {
finish();
startActivity(new Intent(SplashPage.this,MainActivity.class));
}
//prefs.edit().putBoolean("firstrun", false).commit();
//finish();
}
private void calll() {
// TODO Auto-generated method stub
Animation anim = AnimationUtils.loadAnimation(this, R.anim.move);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
iv.startAnimation(anim);
Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.move);
TextView ivvv = (TextView) findViewById(R.id.textView1);
ivvv.startAnimation(anim1);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(SplashPage.this, SplashPageTutorial.class);
startActivity(intent);
overridePendingTransition(R.anim.fade, R.anim.hold);
finish();
}
},
startPage);
}
现在我想做的是,应用程序首次启动时 Splash 运行 7 秒,然后打开下一个屏幕,7 秒后与 splash 链接,然后在第二个屏幕之后我的主屏幕 Activity 开始。 现在我想做的是,当我第一次打开应用程序时,只有 Main Activity 启动(闪屏和与闪屏链接的屏幕现在消失了)
我使用此代码,以便当应用程序再次打开时布尔值 returns false 并启动 Main Activity 但它不会发生
if (prefs.getBoolean("firstrun", true)) {
calll();
}
if (prefs.getBoolean("firstrun", false)) {
finish();
startActivity(new Intent(SplashPage.this,MainActivity.class));
}
//prefs.edit().putBoolean("firstrun", false).commit();
//finish();
请帮忙看看我该怎么办
我的清单是这样的:
<application android:icon="@drawable/appicon"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<activity android:name="com.tech.spam.SplashPage"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.tech.spam.MainActivity"
>
</activity>
<activity
android:name="com.tech.spam.SplashPageTutorial"
android:theme="@style/FullscreenTheme"
>
</activity>
一种简单的方法是共享偏好变量。在启动闪屏时将此变量设置为 true。在启动 activity 之前检查此变量是否为 false 并且仅在它为 false 时启动。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
SharedPreferences settings=getSharedPreferences("prefs",0);
boolean firstRun=settings.getBoolean("firstRun",false);
if(firstRun==false)//if running for first time
//Splash will load for first time
{
SharedPreferences.Editor editor=settings.edit();
editor.putBoolean("firstRun",true);
editor.commit();
Intent i=new Intent(check.this,Splash.class);
startActivity(i);
finish();
}
else
{
Intent a=new Intent(check.this,Main.class);
startActivity(a); // Launch next activity
finish();
}
}
}