我正在使用 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/