如何在android编程中为splash使用wait()方法?

如何在android编程中为splash使用wait()方法?,android,splash-screen,time-wait,Android,Splash Screen,Time Wait,我想为我的android应用程序创造一个亮点。其功能是当应用程序打开时,首先显示启动页面。在从GPS获取第一个数据之前,它将转向主要活动。logcat报告的代码中的wait()有一些问题 import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm

我想为我的android应用程序创造一个亮点。其功能是当应用程序打开时,首先显示启动页面。在从GPS获取第一个数据之前,它将转向主要活动。logcat报告的代码中的wait()有一些问题

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

public class splash extends Activity
{   int waittime;
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.splash);
        final TextView text=(TextView)findViewById(R.id.textView1);
        text.setText("Waiting for the GPS data update!");
        LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        String provider = locationManager.GPS_PROVIDER;
        int c=0;
        for(int i=0; i<20;i++)
        {  
            Location location = locationManager.getLastKnownLocation(provider);
                 //get the location data from every loop
            if(location!=null)//if get the data, then turn to the main activity
            {
                new Handler().postDelayed(new Runnable() {
                    public void run() {

                        Intent mainIntent = new Intent(splash.this, MainActivity.class);
                        splash.this.startActivity(mainIntent);
                    splash.this.finish();
                    }
                }, 1000);
            }
                else
                {
                    try {
                        wait(3000);//if not get the data, wait 3 seconds until the next loop
                    } catch (InterruptedException e) {

                        e.printStackTrace();
                    }
                }
            }

        }
    }
导入android.app.Activity;
导入android.content.Context;
导入android.content.Intent;
导入android.content.pm.PackageInfo;
导入android.content.pm.PackageManager;
导入android.content.pm.PackageManager.NameNotFoundException;
导入android.location.location;
导入android.location.LocationListener;
导入android.location.LocationManager;
导入android.os.Bundle;
导入android.os.Handler;
导入android.widget.TextView;
公共课堂活动
{int waittime;
创建公共空间(捆绑冰柱)
{
超级冰柱;
setContentView(R.layout.splash);
最终文本视图文本=(文本视图)findViewById(R.id.textView1);
setText(“等待GPS数据更新!”);
LocationManager LocationManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
字符串提供程序=locationManager.GPS\U提供程序;
int c=0;
对于(int i=0;i为了调用对象上的wait(),必须持有该对象上的同步锁(尽管锁实际上在线程等待时被释放)。

还有thread.sleep,如果它工作得更好,但我不确定它是否会工作。

使用thread.sleep,而不是像这样的等待()


在这里添加您的logcat消息。帮助很大:)我更新了它并添加了logcat信息。
 try {
            Thread.sleep(1500);
     }
    catch (InterruptedException e)
     {
              e.printStackTrace();
     }