android - 如何像启动画面一样只运行一次 Activity

标签 android android-intent android-activity android-manifest back-stack

在我的应用程序中,我只想在第一次运行时运行启动画面一次,但问题是我已经在 Manifest 中放置了这一行:android:noHistory="true " 如果我按下后退按钮并退出应用程序,效果很好,但请注意该应用程序仍在后台运行,当我按下应用程序图标时,它会再次返回到初始屏幕,然后是我的注册页面。我希望在重新打开我的应用程序时直接重定向到注册页面。

我该怎么做?提前感谢您的任何建议。

最佳答案

这就是我实现它的方式!希望对您有所帮助!

import android.app.Activity;

import android.content.Intent;

import android.content.SharedPreferences;

import android.os.Bundle;

public class check extends Activity{

@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);
        finish();
    }
}

}

关于android - 如何像启动画面一样只运行一次 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18612824/

相关文章:

android - 将 Intent 包装在 LabeledIntent 中以供显示

java - Android - 一个 Activity 中有两个 setViewContent - 一个在 xml 中,一个在 java 中

android - 我可以使用 zxing intents 修改相机预览屏幕吗?

android - Uber 在 android 中提供了无效的 OAuth 2.0 凭据 Uber 身份验证

android - 将多个图像保存到外部存储android

android - 方案主机无法在 android Lollipop 上运行,单击链接以打开应用程序

android - 当父 Activity 作为参数传递给非 Activity 类中的 Intent 时, onActivityResult 不会被 finish() 调用

android - 错误 -505 INSTALL_FAILED_DUPLICATE_PERMISSION :

android - 检查耳机是否插入

android - android中的singleTask launchMode无法正常工作