我从一个调用另一个活动的地方创建了一个启动活动,该活动具有一个视图寻呼机并显示一些介绍性页面。
这个应用程式需要花费一些时间来载入,因此我想在活动载入之前显示一个进度对话框,但该进度对话框也会在几秒钟后出现。
启动活动:
public class StartUpActivity extends AppCompatActivity {
boolean isUserFirstTime, login;
public static String PREF_USER_FIRST_TIME;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isUserFirstTime = Boolean.valueOf(Utils.readSharedSetting(StartUpActivity.this, PREF_USER_FIRST_TIME, "true"));
Intent introIntent = new Intent(StartUpActivity.this, SlidingActivity.class);
introIntent.putExtra(PREF_USER_FIRST_TIME, isUserFirstTime);
ProgressDialog dialog = new ProgressDialog(StartUpActivity.this);
dialog.setMessage("Welcome to Mea Vita, please wait till the app loads.");
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
dialog.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Here you can send the extras.
startActivity(new Intent(StartUpActivity.this,SlidingActivity.class));
// close this activity
finish();
}
}, 4000);
}
}
这并非每次都发生,只是有时。这可能是什么原因?我该如何阻止呢?有什么办法吗?谢谢..
Android Studio 2.0
第一次启动应用程序时,新发布的版本(2.1中存在同样的问题)存在一个奇怪的问题,该问题比平时更长(例如2、3秒或有时屏幕闪烁或变黑),仅在调试模式下才会发生,并且不会影响您发布的APK 。
解决此问题的临时解决方案是禁用instant run
:
Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句