首页 > 解决方案 > App Goes Background When MainActivity Class Called

问题描述

I'm learning Android Development with multiple app's source codes. I opened one of my projects in Android Studio. I developed some part of this app using some open source libraries from GitHub. My problem is app is compiling and I'm able to build APK but when I run it on a device the goes to background (not crashed because when I checked the logcat there is no trace for a crash).

When I'm running the app firstly the SplashScreen class getting loaded (There is no issue with it). After splash screen loaded it should open MainActivity class but it goes to background (As I already said that's not even a crash)

Here's SplashActivity's code :

public class SplashActivity extends BaseActivity {

private void runSplash() {
    new CountDownTimer(TimeUnit.SECONDS.toMillis(3), 100) {
        public void onTick(long j) {
         onFinish()

            }

        public void onFinish() {
            SplashActivity.this.startActivity(new      Intent(SplashActivity.this, MainActivity.class));
            SplashActivity.this.finish();
        }


    }.start();
}

protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_splash);
    runSplash();
}

protected void onDestroy() {
    super.onDestroy();
}
}

UPDATE: The issue is now resolved. The problem is with exception handling inside the onCreate method. Whatever exception happens then the activity getting finished (finish();). Thanks for helping me to understand.

After Splash Activity finished MainActivity Should be shown but the app goes background. I even tried ignoring Splash Activity and just MainActivity as a Launcher in Manifest file. But the same problem (As soon as app launched it goes to background)

标签: javaandroidandroid-activity

解决方案


在您的 MainActivity onCreate() 中,您有一个巨大的 try/catch 块,如果引发异常,您将完成 () 活动...

您必须记录异常Log.e("YOUR_TAG", e.getMessage())以了解您的错误:)


推荐阅读