一個活動,我有兩個Activities
名爲LoginActivity
和RegistrationActivity
。我從LoginActivity
開始RegistrationActivity
使用Intent
單擊按鈕。但問題是有一個延遲2到3秒加載RegistrationActivity
。可能是什麼問題?延遲,同時開始從另一個
LoginActivity
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
setup();
}
private void setup() {
layout = (RelativeLayout) findViewById(R.id.loginLayout);
register = (Button) findViewById(R.id.registerText);
email = (AppCompatEditText) findViewById(R.id.loginEmail);
password = (AppCompatEditText) findViewById(R.id.loginPassword);
submit = (Button) findViewById(R.id.loginSubmit);
submit.setOnClickListener(listener);
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(LoginActivity.this, RegistrationActivity.class);
ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight());
ActivityCompat.startActivity(LoginActivity.this,
intent, options.toBundle());
}
});
}
RegistrationActivity
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_registration);
}
@Override
protected void onStart() {
super.onStart();
setup();
new getLatLongAsync().execute();
}
private class getLatLongAsync extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
}
@Override
protected String doInBackground(String... args) {
mGoogleApiClient = new GoogleApiClient.Builder(RegistrationActivity.this)
// The next two lines tell the new client that 「this」 current class will handle connection stuff
.addConnectionCallbacks(RegistrationActivity.this)
.addOnConnectionFailedListener(RegistrationActivity.this)
//fourth line adds the LocationServices API endpoint from GooglePlayServices
.addApi(LocationServices.API)
.build();
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(1000); // 1 second, in milliseconds
return null;
}
protected void onPostExecute(String args) {
mGoogleApiClient.connect();
}
}
getLatLong()
獲得緯度和經度:
private void getLatLong() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
// The next two lines tell the new client that 「this」 current class will handle connection stuff
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
//fourth line adds the LocationServices API endpoint from GooglePlayServices
.addApi(LocationServices.API)
.build();
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(1000); // 1 second, in milliseconds
}
可能是由於製作動畫是越來越delay.check嘗試這種只看到如果獲取延遲與否,意向意圖=新意圖(LoginActivity.this,RegistrationActivity.class); startActivity(intent); –
我試過沒有動畫。相同的結果。 – XoXo
請致電getLatLong();在AsyncTask或Thread中。調用函數getLatLong();可能會延遲負載。 – Sanil