Bạn có thể làm một cái gì đó như thế trong manifest để cho phép quay:
<application
android:allowBackup="true"
android:configChanges="orientation|keyboardHidden|screenSize"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".activities.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"/>
Sau đó, bạn có thể nắm bắt được luân chuyển với snipet này bên trong hoạt động của bạn:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.v(this.getClass().getName(), "onConfigurationChanged()");
}
Để làm một AsyncTask với hộp thoại tiến bộ , snipet này sẽ cung cấp cho bạn một ligth:
private ProgressDialog pDialog;
private class MyAsync extends AsyncTask<String, Void, String> {
Activity context;
public MyAsync (Activity context) {
this.context = context;
}
@Override
protected void onPreExecute(){
super.onPreExecute();
pdia = new ProgressDialog(context);
pdia.setMessage("Loading...");
pdia.show();
}
@Override
protected String doInBackground(String... urls) {
...
//do your login scheme
...
//context.methods()
return "ok";
}
@Override
protected void onPostExecute(String result) {
pDialog.dismiss();
if(result!=null && result.equals("ok")){
//login was successfully done
} else {
//login has failed
}
}
}
Và để sử dụng asynctas này k bạn shoud gọi:
new MyAsync(this).execute(null, null , null);
Bằng cách này this
là hoạt động/phân đoạn của bạn.
bạn có thể giải thích những gì bạn muốn làm gì? – Singh
@Singh tôi muốn đăng nhập với máy chủ hiển thị tiến trình và cho phép điện thoại xoay mà không giết chết hành động đăng nhập –
Về mặt kỹ thuật, có một giải pháp sử dụng từng khối trong số ba khối xây dựng Android. Tôi có thể đề nghị IntentService ít nhất gắn liền với vòng đời của hoạt động ... nhưng sau đó kết nối nó thông qua các chương trình phát sóng thì phức tạp hơn việc sử dụng AsyncTask. Nó thực sự sẽ là tốt nhất cho một câu hỏi SO để thử một trong những phương pháp này và cộng đồng có thể hỗ trợ từ đó. – FishStix