У меня есть основная активность, из которой я называю Splash Screen Intent, которая уничтожает себя через 3 секунды, но между жизненным циклом Splash Screen Intent основная активность также разрушает (что неправильно!) .. поэтому, когда намерение Splash Screen завершено, приложение вылетает из-за того, что основная активность была уничтожена сама.Основная деятельность Destroyed before Splash Screen return
Я действительно ценю, если кто-то может помочь мне в этом, у меня действительно нет идей на этом этапе.
Вот мой код:
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);
this.onNewIntent(this.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("PORTAL"));
}
} 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);
}
}
вот part of logcat
Это не имеет особого смысла. 'this.onNewIntent (this.getIntent());' вызывается из 'onCreate'.Значение по умолчанию 'authCode', вероятно, не' OK', поэтому вы начнете операцию 'ErrorIntent',' finish() 'your' MainActivity', а затем запустите операцию' SplashIntent'. Как вы хотите, чтобы это работало точно? Когда установлен 'authCode'? –
После всех этих проверок всегда отображается экран заставки (3 секунды), а затем основная активность @GeorgeMulligan –