とRegistrationActivity
の2つのActivities
があります。 Intent
を使用してボタンをクリックするとがLoginActivity
から開始しています。しかし、問題はの遅延が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
}
アニメーションのために遅延が発生している可能性があります。これを試してみると、遅延が発生するかどうかを確認するためのチェックが行われます。インテントの意図=新しいインテント(LoginActivity.this、RegistrationActivity.class)。 startActivity(インテント); –
私はアニメーションなしで試しました。同じ結果。 – XoXo
getLatLong()を呼び出してください。内部AsyncTaskまたはスレッド。関数getLatLong()を呼び出します。負荷を遅延させる可能性があります。 – Sanil