【问题标题】:Create a Loading Screen without a specific time创建没有特定时间的加载屏幕
【发布时间】:2015-08-18 14:15:42
【问题描述】:

这是我的问题,当我打开一个活动时,它开始使用本机方法 (jni) 处理图像,我不想要黑屏,我想显示等待消息或加载轮。

我无法确定图像处理需要多长时间。

【问题讨论】:

  • 使用不确定的ProgressDialog
  • 已经尝试了什么?
  • 我都试过了,但问题是我不能在线程内部调用本地方法。我该怎么做?

标签: android screen loading


【解决方案1】:

这样做并为我工作:

final ProgressDialog progress;
            progress = ProgressDialog.show(PlayStaff.this, "Loading",
                    "Processing Image", true);

        new Thread(new Runnable() {
            @Override
            public void run() {
                // do the thing that takes a long time
                processImageNativeMethodJNI();

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        progress.dismiss();
                    }
                });
            }
        }).start();

【讨论】:

    【解决方案2】:

    你也可以在这里使用 Handler。

    private static int SPLASH_TIME_OUT = 3000;
    
     new Handler().postDelayed(new Runnable() {
    
            @Override
            public void run() {
    
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);               
            }
        }, SPLASH_TIME_OUT);
    

    您可以在您的 Spalshscreen.java 文件和它的布局文件中添加任何其他动画、消息和所有内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 2013-07-23
      相关资源
      最近更新 更多