위치 사용자 Android 동안 검은 색 화면 대신 시작 화면 표시

나탈리 카

안녕하세요 저는 사용자 위치 좌표를 찾는 서비스가 있습니다. 이 서비스는 onCreate내 MainActivity에서 시작됩니다 . 그러나 GPS가 좌표를 찾는 데 시간이 걸릴 수 있다는 것을 알고있는 값을 찾을 때까지 화면이 검은 색입니다. 표시하고 싶은 스플래시 화면을 만들었지 만 구현 방법을 잘 모르겠습니다. 내 코드는 더 자세히 설명합니다.

내 서비스 :

public class LocationService extends Service implements
 GooglePlayServicesClient.ConnectionCallbacks,
 GooglePlayServicesClient.OnConnectionFailedListener,
    LocationListener {

    public static double curlat;
    public static double curlong;
    IBinder mBinder = new LocalBinder();

   private LocationClient mLocationClient;
   private LocationRequest mLocationRequest;
   // Flag that indicates if a request is underway.
   private boolean mInProgress;

   public static final String BROADCAST_ACTION =  "com.example.fusedlocation.displayevent";
   Intent intent;

   private Boolean servicesAvailable = false;

   public class LocalBinder extends Binder {
    public LocationService getServerInstance() {
        return LocationService.this;
    }
   }

   @Override
    public void onCreate() {
       super.onCreate();


       intent = new Intent(BROADCAST_ACTION);

       mInProgress = false;
       // Create the LocationRequest object
       mLocationRequest = LocationRequest.create();
       // Use high accuracy
       mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
       // Set the update interval to 5 seconds
       mLocationRequest.setInterval(Constants.UPDATE_INTERVAL);
       // Set the fastest update interval to 1 second
       mLocationRequest.setFastestInterval(Constants.FASTEST_INTERVAL);

       servicesAvailable = servicesConnected();

       /*
        * Create a new location client, using the enclosing class to
        * handle callbacks.
        */
       mLocationClient = new LocationClient(this, this, this);


   }

   private boolean servicesConnected() {

       // Check that Google Play services is available
       int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

       // If Google Play services is available
       if (ConnectionResult.SUCCESS == resultCode) {

           return true;
       } else {

           return false;
       }
   }

   public int onStartCommand (Intent intent, int flags, int startId)
   {
       super.onStartCommand(intent, flags, startId);

       if(!servicesAvailable || mLocationClient.isConnected() || mInProgress)
        return START_STICKY;

       setUpLocationClientIfNeeded();
       if(!mLocationClient.isConnected() || !mLocationClient.isConnecting() && !mInProgress)
       {
        appendLog(DateFormat.getDateTimeInstance().format(new Date()) + ": Started", Constants.LOG_FILE);
        mInProgress = true;
        mLocationClient.connect();
       }

       return START_STICKY;
   }

    /*
    * Create a new location client, using the enclosing class to
    * handle callbacks.
    */
   private void setUpLocationClientIfNeeded()
   {
    if(mLocationClient == null) 
           mLocationClient = new LocationClient(this, this, this);
   }

   // Define the callback method that receives location updates
   @Override
   public void onLocationChanged(android.location.Location location) {
       // Report to the UI that the location was updated
       String msg = Double.toString(location.getLatitude()) + "," +
               Double.toString(location.getLongitude());
       Log.d("debug", msg);
       curlat = location.getLatitude();
       curlong = location.getLongitude();
       // Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
       appendLog(msg, Constants.LOCATION_FILE);

       intent.putExtra("Latitude", location.getLatitude());
       intent.putExtra("Longitude", location.getLongitude());
       sendBroadcast(intent, null);

   }

   @Override
   public IBinder onBind(Intent intent) {
    return mBinder;
   }

   public String getTime() {
    SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return mDateFormat.format(new Date());
   }

   public void appendLog(String text, String filename)
   {       
      File logFile = new File(filename);
      if (!logFile.exists())
      {
         try
         {
            logFile.createNewFile();
         } 
         catch (IOException e)
         {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }
      try
      {
         //BufferedWriter for performance, true to set append to file flag
         BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
         buf.append(text);
         buf.newLine();
         buf.close();
      }
      catch (IOException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

   @Override
   public void onDestroy(){
       // Turn off the request flag
       mInProgress = false;
       if(servicesAvailable && mLocationClient != null) {
            mLocationClient.removeLocationUpdates(this);
            // Destroy the current location client
            mLocationClient = null;
       }
       // Display the connection status
       // Toast.makeText(this, DateFormat.getDateTimeInstance().format(new Date()) + ": Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show();
       appendLog(DateFormat.getDateTimeInstance().format(new Date()) + ": Stopped", Constants.LOG_FILE);
       super.onDestroy();  
   }

   /*
    * Called by Location Services when the request to connect the
    * client finishes successfully. At this point, you can
    * request the current location or start periodic updates
    */
   @Override
   public void onConnected(Bundle bundle) {

       // Request location updates using static settings
       mLocationClient.requestLocationUpdates(mLocationRequest, this);
       appendLog(DateFormat.getDateTimeInstance().format(new Date()) + ": Connected", Constants.LOG_FILE);
   }


   /*
    * Called by Location Services if the connection to the
    * location client drops because of an error.
    */
   @Override
   public void onDisconnected() {
       // Turn off the request flag
       mInProgress = false;
       // Destroy the current location client
       mLocationClient = null;
       // Display the connection status
       // Toast.makeText(this, DateFormat.getDateTimeInstance().format(new Date()) + ": Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show();
       appendLog(DateFormat.getDateTimeInstance().format(new Date()) + ": Disconnected", Constants.LOG_FILE);
   }

   /*
    * Called by Location Services if the attempt to
    * Location Services fails.
    */
   @Override
   public void onConnectionFailed(ConnectionResult connectionResult) {
    mInProgress = false;

       /*
        * Google Play services can resolve some errors it detects.
        * If the error has a resolution, try sending an Intent to
        * start a Google Play services activity that can resolve
        * error.
        */
       if (connectionResult.hasResolution()) {

       // If no resolution is available, display an error dialog
       } else {

       }
   }   

}

MainActivity (관련 부분 만) :

public class MainActivity extends Activity implements
        GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener{

    // Google Map & markers
    private GoogleMap googleMap;
    private Circle mCircle;
    private Marker mMarker;
    double radiusInMeters;

    long start_time, countUp, timeDialogShown = 0;
    double latitude, longitude, startLongitude, startLatitude;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Setting the layout
        setContentView(R.layout.activity_main);

        try {
            // Loading map
            initilizeMap();
        } catch (Exception e) {
            e.printStackTrace();
        }

        startService(new Intent(this, LocationService.class));

    } // end onCreate

    //Checking the latest location updates
    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            Bundle extras = intent.getExtras();
             latitude = extras.getDouble("Latitude");
             longitude = extras.getDouble("Longitude");

             LatLng latLng = new LatLng(latitude, longitude);

            if (mCircle == null || mMarker == null) {
                drawMarkerWithCircle(latLng);
            } else {
                updateMarkerWithCircle(latLng);
            }

            getDistance();
            //Getting the current weather conditions
            //if (condDescr.getText().equals(" ")){
            //  getWeatherConditions();
            //}

            //Check if the user has breached the Geofence boundaries
            checkBoundaries();
            }

    };
라난

여기에서 내 대답을 확인하십시오 : Android SplashScreen

기본적으로 테마 배경을 만들면 콘텐츠를 설정할 때까지 검은 화면이 처리됩니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

로드하는 동안 Android가 스플래시 화면을 표시하지만 대신 검은 색 화면이 표시됨

분류에서Dev

사용자 지정 Android 커널에 검은 색 화면 표시

분류에서Dev

LaunchScreen.xib 대신 검은 색 화면이 표시됨

분류에서Dev

화면에 그림을 표시하는 동안 검은 색 화면

분류에서Dev

Android 7.1에서 검은 색 막대가있는 콜드 시작 시작 화면

분류에서Dev

간단한 SceneKit 장면에 SCNPlane 대신 검은 색 화면이 표시됨

분류에서Dev

간단한 SceneKit 장면에 SCNPlane 대신 검은 색 화면이 표시됨

분류에서Dev

안전 모드가 작동하는 동안 부팅시 검은 색 화면

분류에서Dev

설치시 검은 색 화면

분류에서Dev

데비안 설치시 검은 색 화면

분류에서Dev

Android : 스플래시 화면 후 검은 색 화면이 나옴

분류에서Dev

Android Studio GDX, 스플래시 화면 후 검은 색 화면

분류에서Dev

바탕 화면에 배경 화면 대신 흰색 또는 검은 색 배경이 표시됨

분류에서Dev

Nexus 7에서 Android 앱이 시작되지 않음 (검은 색 화면 표시)

분류에서Dev

사진 촬영 후 Android 앱에 검은 색 화면이 표시되지만 디버거에 연결하면 작동합니다.

분류에서Dev

SurfaceView에 검은 색 화면이 표시됨-Android

분류에서Dev

GLSurfaceView의 스크린 샷을 캡처하는 동안 검은 색 화면 표시

분류에서Dev

사용자 전환시 빈 검은 색 화면

분류에서Dev

UINavigationController에 대한 Custom Segue에 검은 색 화면이 표시됨

분류에서Dev

Android : Hashset 내에서 문자열을 색상에 일치-화면에 무작위로 표시됩니까?

분류에서Dev

Angular 앱이 iOS에서 시작 화면 후 검은 색 화면을 표시 함

분류에서Dev

ionic 앱을 시작하는 동안 빈 흰색 화면 표시

분류에서Dev

View Controller에 Firebase 데이터베이스 Swift iOS에서 사용자를 가져 오는 대신 검은 색 화면이 표시됨

분류에서Dev

Ubuntu 16.04.1 Nvidia가 작동하지만 Intel에 검은 색 화면이 표시됨

분류에서Dev

일정 시간 동안 사용하지 않으면 대화 상자 표시

분류에서Dev

Chrome (OS?) 용 DOSBOX가 검은 색 화면으로 표시됨

분류에서Dev

검은 색 화면 + "시스템 업데이트를 설치하는 동안 잠시 기다려주십시오."

분류에서Dev

BIOS 시작 화면 후 검은 색 화면

분류에서Dev

Unity 5.3.0의 Android 6.0.1에서 시작시 검은 색 화면 (스플래시 화면 없음)

Related 관련 기사

  1. 1

    로드하는 동안 Android가 스플래시 화면을 표시하지만 대신 검은 색 화면이 표시됨

  2. 2

    사용자 지정 Android 커널에 검은 색 화면 표시

  3. 3

    LaunchScreen.xib 대신 검은 색 화면이 표시됨

  4. 4

    화면에 그림을 표시하는 동안 검은 색 화면

  5. 5

    Android 7.1에서 검은 색 막대가있는 콜드 시작 시작 화면

  6. 6

    간단한 SceneKit 장면에 SCNPlane 대신 검은 색 화면이 표시됨

  7. 7

    간단한 SceneKit 장면에 SCNPlane 대신 검은 색 화면이 표시됨

  8. 8

    안전 모드가 작동하는 동안 부팅시 검은 색 화면

  9. 9

    설치시 검은 색 화면

  10. 10

    데비안 설치시 검은 색 화면

  11. 11

    Android : 스플래시 화면 후 검은 색 화면이 나옴

  12. 12

    Android Studio GDX, 스플래시 화면 후 검은 색 화면

  13. 13

    바탕 화면에 배경 화면 대신 흰색 또는 검은 색 배경이 표시됨

  14. 14

    Nexus 7에서 Android 앱이 시작되지 않음 (검은 색 화면 표시)

  15. 15

    사진 촬영 후 Android 앱에 검은 색 화면이 표시되지만 디버거에 연결하면 작동합니다.

  16. 16

    SurfaceView에 검은 색 화면이 표시됨-Android

  17. 17

    GLSurfaceView의 스크린 샷을 캡처하는 동안 검은 색 화면 표시

  18. 18

    사용자 전환시 빈 검은 색 화면

  19. 19

    UINavigationController에 대한 Custom Segue에 검은 색 화면이 표시됨

  20. 20

    Android : Hashset 내에서 문자열을 색상에 일치-화면에 무작위로 표시됩니까?

  21. 21

    Angular 앱이 iOS에서 시작 화면 후 검은 색 화면을 표시 함

  22. 22

    ionic 앱을 시작하는 동안 빈 흰색 화면 표시

  23. 23

    View Controller에 Firebase 데이터베이스 Swift iOS에서 사용자를 가져 오는 대신 검은 색 화면이 표시됨

  24. 24

    Ubuntu 16.04.1 Nvidia가 작동하지만 Intel에 검은 색 화면이 표시됨

  25. 25

    일정 시간 동안 사용하지 않으면 대화 상자 표시

  26. 26

    Chrome (OS?) 용 DOSBOX가 검은 색 화면으로 표시됨

  27. 27

    검은 색 화면 + "시스템 업데이트를 설치하는 동안 잠시 기다려주십시오."

  28. 28

    BIOS 시작 화면 후 검은 색 화면

  29. 29

    Unity 5.3.0의 Android 6.0.1에서 시작시 검은 색 화면 (스플래시 화면 없음)

뜨겁다태그

보관