我開發了一個應用程序與Wi-Fi連接。在該應用程序縱向/橫向轉換時,在旋轉手機並中斷套接字連接時重新啓動活動。然後我添加肖像到AndroidManifest.xml
文件,然後問題得到解決。我想知道這是對Async-Task的縱向/橫向轉換效果嗎?是AsyncTask的縱向/橫向過渡效果
<activity
android:name="login"
android:label="@string/login_title"
android:configChanges="orientation|screenSize" >
</activity>
Login.java文件
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class login extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
try{
Button buttonSignin = (Button) this.findViewById(R.id.btnSignIn);
//This is the place gives nullpointerException
buttonSignin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText user=(EditText) findViewById(R.id.txtUserName);
EditText pass=(EditText) findViewById(R.id.txtPassword);
if(user.getText().toString()== "")
{
return;
}
else if(pass.getText().toString()== "")
{
return;
}
else
{
LoginRequest reqs_login = new LoginRequest(login.this,login.this);
reqs_login.where="Login_Data";
reqs_login.title="Login";
reqs_login.username=user.getText().toString();
reqs_login.password=pass.getText().toString();
reqs_login.execute();
}
}
});
} catch (NullPointerException e) {
e.printStackTrace();
//Toast.makeText(getBaseContext(), "Error:1 on uplod file", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
//Toast.makeText(getBaseContext(), "Error:2 File may be already exists", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
}
http://stackoverflow.com/questions/3821423/background-task-progress-dialog-orientation-change-is-there-any-100-working –
張貼您的登錄xml文件 – Piyush
什麼是新的LoginRequest (login.this,login.this)... ?? – Ranjit