I want to fetch user's location on a splash screen, and after fetching location, splash screen must end.
I want to store the latitude and longitude in two strings.
Here is my code : SplashScreen.java
package com.example.black_ghost.miniproject;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import com.google.android.gms.common.CoectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
public class SplashScreen extends AppCompatActivity implements GoogleApiClient.CoectionCallbacks, GoogleApiClient.OnCoectionFailedListener
{
private Location mLastLocation;
public LocationManager mLocationManager;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
Thread t=new Thread()
{
public void run()
{
try
{
sleep(2000);
finish();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SplashScreen.this);
if(!prefs.getBoolean("firstTime", false))
{
// run your one time code
Intent cv=new Intent(SplashScreen.this,FirstTimeActivity.class);
startActivity(cv);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("firstTime", true);
editor.commit();
}else
{
Intent cv=new Intent(SplashScreen.this,MainActivity.class);
startActivity(cv);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
};
t.start();
}
@Override
public void onCoected(Bundle bundle) {
}
@Override
public void onCoectionSuspended(int i) {
}
@Override
public void onCoectionFailed(CoectionResult coectionResult) {
}
}
I am new to android, and I have to submit this assignment, please help I want to store the latitude and longitude in two strings.
