将 Activity 替换为 Manifest.xml

Replace Activity in Manifest.xml

当我 运行 我的应用程序时,它将 运行 MainActivity 首先根据 ManiFest.xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="bizsalt.drawer2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/gargi_blue"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="XYZ"
            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>

</manifest>

工作正常但现在我想 add SplashScreenActivity , LoginActivityRegisterActivity MainActivity 之前。

所以我怎么能Change the Order of Activity。首先使用 SplashScreenActivity 启动应用程序然后 LoginActivityRegisterActivity 然后 MainActivity.


如果我使用此代码它工作正常但显示标题。如何删除它。

CircularProgressView progressView2;
private static int SPLASH_TIME_OUT = 5000;

@Override
protected void onCreate(Bundle savedInstanceState) {

    // Remove the Title Bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    super.onCreate(savedInstanceState);
    // Get the view from splash_screen.xml
    setContentView(R.layout.activity_splash_screen);


    CircularProgressView progressView2 = (CircularProgressView)findViewById(R.id.progress_view10);
    progressView2.setColor(Color.parseColor("#FFFFFF"));

    new Handler().postDelayed(new Runnable() {


        @Override
        public void run() {

            finish();
            Intent myIntent = new Intent(SplashScreenActivity.this,
                    LoginActivity.class);
            startActivity(myIntent);
        }
    }, SPLASH_TIME_OUT);

}

So How I can Change the Order of Activity

你不能从 manifest 改变 activity 的顺序,你可以定义启动器 activity 但是从那里你需要写java 文件中你自己的逻辑和代码。

在 JAVA 文件中执行任何操作之前,您需要在清单文件

中定义 activity

Intent 将用于启动新的 Activity。查看以下链接以获取更多信息。

Intent
Starting Another Activity

您必须更改清单:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="bizsalt.drawer2">

        <application
            android:allowBackup="true"
            android:icon="@mipmap/gargi_blue"
            android:label="@string/app_name"
            android:theme="@style/AppTheme">
            <activity
                android:name=".SplashScreenActivity"
                android:label="XYZ"
                android:theme="@style/AppTheme">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".LoginActivity"
                android:label="XYZ"
                android:theme="@style/AppTheme"
              />
             <activity
                android:name=".RegisterActivity"
                android:label="XYZ"
                android:theme="@style/AppTheme"
              /> 
             <activity
                android:name=".MainActivity"
                android:label="XYZ"
                android:theme="@style/AppTheme"
              />
    </application>
    </manifest>

在您的 SplashScreenActivity 中。放代码中转LoginActivity:

Intent mIntent = new Intent(SplashScreenActivity.this,LoginActivity.class);
startActivity(mIntent);

对其他人做同样的事情Activity

<activity
            android:name=".SplashScreenActivity"
            android:label="XYZ"
            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

<activity
        android:name=".LoginActivity "
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme" />

<activity
        android:name=".RegisterActivity"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme" />

并在启动画面中打开您想要打开的任何一个 activity,例如通过单击按钮或计时器以及其他活动。

改变

android:name=".MainActivity" 

在您的 manifest.xml 文件中

android:name=".SplashScreenActivity"

在 SplashScreenActivity 中,在启动画面完全加载后添加这行代码

Intent loginIntent = new Intent(SplashScreenActivity.this, LoginActivity.class);
startActivity(loginIntent);

在LoginActivity中,如果用户登录成功则转到Mainactivity

Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);

日志也说了解决方案

不要在 requestFeature() 之前调用 setContentView()

可能是您没有在清单中添加所有活动 file.If 您没有这样做并且仍然从您的应用崩溃的意图中调用 activity。 所以首先是你想要的activity,通过如下相同的意图过滤器:

   <activity
                android:name=".SplashScreenActivity"
                android:label="XYZ"
                android:theme="@style/AppTheme">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

其次,无论您创建什么 activity,都将其添加到清单中,现在不要以这种方式为任何 other.Add 提供过滤器

<activity
                android:name=".MainActivity"
                android:label="XYZ"
                android:theme="@style/AppTheme"
              />

第三次将意图从您当前的 activity 传递到您要切换的 activity

   Intent int = new Intent(SplashScreenActivity.this,MainActivity.class);
    startActivity(int);

如果仍然出现任何问题 post 您的 logcat。 祝你好运!!