java - 启动画面和第二个 Activity 返回

标签 java android android-activity

我正在使用 Android studio 编写一个简单的应用程序,它打开主要 Activity ,当我单击按钮时,它会产生新的 Intent ,以便在网络浏览器中启动 URL。打开URL的代码是:

String Link=listURL.get((int) id).toString();
                Uri uriUrl = Uri.parse(Link);
                Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                startActivity(launchBrowser);

它工作正常,它显示网络结果,我可以使用后退按钮返回主要 Activity 。一切都工作正常,直到我决定使用闪屏。 实现启动屏幕后,当我单击网络浏览器中的后退按钮时,它会从应用程序退出。它不会再出现在“主要” Activity 中。

这里是我的manifest.xml: 如果我尝试删除 .splashscreen 节,一切正常。我没有启动画面,但一切正常。可能是 list 的属性问题?

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".SplashScreen"
        android:theme="@android:style/Theme.Translucent"
        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=".MyActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAINACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

这是我的启动屏幕:

public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Thread timerThread = new Thread(){
        public void run(){
            try{
                sleep(1000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent intent = new Intent(SplashScreen.this,MyActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        }
    };
    timerThread.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

}

谢谢 乔瓦尼

最佳答案

执行语句后调用 finish() 导致启动 MyActivity

 Intent intent = new Intent(SplashScreen.this,MyActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
 finish();

避免在 onPause() 中调用 finish()。

关于java - 启动画面和第二个 Activity 返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34564813/

相关文章:

java - String 是 Android 或 Java 中的原语还是对象?

android - 如何获取未在 Android Activity 中单击的按钮的时间

android)我可以设置一个在安装后立即运行的默认 Activity 吗

java - JVM 上的汇编编程?

java - 在*多线程* Swing 应用程序中使用 Hibernate 进行 session 管理

android - 在 Activity 中实现 SQLite 和 Cursor 的问题

java - 表达式的类型必须是数组类型,但它解析为 long

android - 如何将自定义图像设置为不在可绘制文件夹内的背景

java-8 - Stream<T>接口(interface)中filter()方法的实现在哪里?

java - 我如何在 Android 的 onpostexecute() 中构建表格?