我正在写一个简单的应用程序,使用Android工作室打开主要活动,当我点击按钮时,它会创建新的意图,以便在Web浏览器中启动URL。打开网址的代码是:splashscreen和第二个活动返回
String Link=listURL.get((int) id).toString();
Uri uriUrl = Uri.parse(Link);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
它工作正常,它显示了网页的搜索结果,我可以使用后退按钮回来的主要活动。所有的工作都很好,直到我决定使用启动画面。 执行启动画面后,当我点击浏览器中的后退按钮时,它将退出应用程序。它不会再回到“主要”活动中。
这里我的manifest.xml: 如果我尝试删除.splashscreen节,所有工作正常。我没有启动画面,但所有的作品。可能是清单的属性问题?
<?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();
}
}
感谢 乔瓦尼
可以探测评论行“intent.addFlags ......”,并把完成()调用下面startActivity(意向)。删除也完成()调用Pause方法。 –