gpt4 book ai didi

java - 如何在 SplashScreen 之后启动另一个 Activity。启动画面在给定的计时器之后崩溃

转载 作者:行者123 更新时间:2023-12-01 12:00:41 25 4
gpt4 key购买 nike

我是一名大学生,刚刚开始从事 Android 工作。我的启动屏幕在超时后崩溃,但下一个 Activity 页面没有显示。我怎样才能克服这个问题?

这是我的 SplashScreen.java:

public class SplashScreen extends ActionBarActivity {

private final int SPLASH_DISPLAY_TIMER = 5000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent mainIntent = new Intent(SplashScreen.this,Menu.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
}
},SPLASH_DISPLAY_TIMER);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

这是我的 loginActivity.java,必须在 SplashScreen 之后启动:

public class loginActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Context context = getApplicationContext();
CharSequence text = "Please fill your login details!";
int duration = Toast.LENGTH_LONG;

Toast toast = Toast.makeText(context, text, duration);
toast.show();
toast.setGravity(Gravity.CENTER,0,0);
loginActivity.this.startActivity(intent);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_login, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

这是我的 AndroidManifest.xml:

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

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
>
<activity
android:name=".SplashScreen"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<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_login"
android:parentActivityName=".SplashScreen"
android:theme="@style/Theme.AppCompat.Light">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.ambuj.supercabs.SplashScreen" />
</activity>
</application>

</manifest>

最佳答案

删除

Intent mainIntent = new Intent(SplashScreen.this,Menu.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();

Intent mainIntent = new Intent(SplashScreen.this,LoginActivity.class);
startActivity(mainIntent);
finish();

关于java - 如何在 SplashScreen 之后启动另一个 Activity。启动画面在给定的计时器之后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27997491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com