【发布时间】:2016-02-09 12:58:10
【问题描述】:
我有一个 SplashScreen 和一个 MainActivity,当应用程序启动时它会显示启动画面(3 秒延迟)然后是 MainActivity,但是当我单击 mi 应用程序的 BarNotification(应用程序外部)时,启动画面显示(3秒延迟)和应用程序崩溃,在 LogCat 中,他 MainActivity 在 Splash Screen Intent LifeCycle 之间自行销毁。 (在第 29,30 行 logcat)
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/browser"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@color/white"
>
<ImageView android:layout_width="wrap_content"
android:contentDescription="splash screen"
android:id="@+id/splash"
android:src="@drawable/splash"
android:layout_height="wrap_content"
android:scaleType="centerInside"/>
</LinearLayout>
为什么我无法通过栏通知正确启动应用程序?
这是一些代码:
MainActivity.java
public class MainActivity extends Activity {
private WebView webview;
public MainActivity() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
log.debug("onCreate(): " + savedInstanceState);
MyApplication.startSomeMobileCore(this);
MyApplication.startSomeMobileNotifier(this);
setContentView(R.layout.main);
onNewIntent(getIntent());
}
@Override
protected void onStart() {
log.debug("onStart()");
super.onStart();
}
@Override
protected void onRestart() {
super.onRestart();
this.wasRestarted = true;
}
@Override
protected void onResume() {
super.onResume();
}
protected void onPause() {
super.onPause();
this.receivedIntent = false;
}
protected void onStop() {
super.onStop();
this.receivedIntent = false;
}
public void onDestroy() {
super.onDestroy();
}
@Override
public void onNewIntent(Intent intent) {
log.debug("onNewIntent(): " + intent);
super.onNewIntent(intent);
if(intent == null) {
log.warn("Received null intent, will ignore");
}
if ("OK".equals(authCode)) {
if (intent != null && intent.getData() != null &&
("content".equals(intent.getData().getScheme()) ||
"http".equals(intent.getData().getScheme()))) {
log.debug("intent.getData() :" + intent.getData() + "; intent.getData().getScheme() : " + intent.getData().getScheme());
String requestedPath;
if ("http".equals(intent.getData().getScheme())) {
requestedPath = URLDecoder.decode(intent.getData().toString());
} else {
requestedPath = intent.getData().getPath();
}
showResource(requestedPath);
} else {
log.debug("Intent without data -> go to entry page after splash screen");
showResource(Configuration.properties.getProperty(""));
}
} else {
Intent errorIntent = new Intent(this, ErrorIntent.class);
startActivity(errorIntent);
// finish actual activity
finish();
}
log.debug("Show splash screen");
Intent intentSplash = new Intent(this, SplashIntent.class);
startActivity(intentSplash);
}
void showResource(String resourceToShow) {
webview = (WebView)findViewById(R.id.browser);
webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.loadUrl(resourceToShow);
}
}
SplashIntent.java
public class SplashIntent extends Activity {
// Time splash screen should be shown (in ms)
private static final int splashTime = 3000;
static Logger log = Logger.getLogger(SplashIntent.class);
@Override
public void onCreate(final Bundle savedInstanceState) {
log.debug("SplashIntent: onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
log.debug("SplashIntent: killing splash");
finish();
}
}, splashTime);
}
}
希望你们能帮我解决这个问题......我现在真的没有想法
【问题讨论】:
-
堆栈跟踪也会有所帮助。编辑:对不起,我刚刚意识到你添加了链接。
-
不要在run()中完成splashActivity,而是在run()方法中使用intent移动到MainActivity()
-
您的主要活动是否已声明为全球活动?
-
当我从 SplashIntent 移动到 Main Activity 时,我得到一个循环,其中 SplashINtent 执行 n 次并且永远不会到达 MainActivity @kishorepatel
-
试试这个代码:
codemSplashThread = new Thread() { @Override public void run() { try { synchronized (this) { wait(2000); } } catch (InterruptedException ex) { } finish();意图意图 = new Intent(); intent.setClass(sPlashScreen, SlideMainActivity.class);开始活动(意图); } }; mSplashThread.start();code
标签: java android splash-screen