java - 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)
解决方案
在您的 MainActivity onCreate() 中,您有一个巨大的 try/catch 块,如果引发异常,您将完成 () 活动...
您必须记录异常Log.e("YOUR_TAG", e.getMessage())
以了解您的错误:)
推荐阅读
- html - 为移动网站设置不同的高度/宽度
- c# - EF-Migration:忽略模型的部分重叠有界上下文
- python - Python 描述递归生成器调用/生成堆栈
- c# - 使用 Regex 开头的 Guid 字段过滤 mongodb 文档
- google-chrome-extension - chrome.PageAction.hide(tabId) 没有按预期工作
- if-statement - If then 语句使用两个不同的日期范围
- java - 从 Ant 运行 JUnit 时如何配置测试超时?
- kotlin - 在 runBlocking 中使用 coroutineScope 有什么效果?
- c# - .NET Core 通过 Docker 部署到 Droplet 错误:已使用运行时阶段名称
- sql - PLS-00103:在预期以下情况之一时遇到符号“文件结尾”:如果