0

検索しましたが、答えが見つかりませんでした。startActivity(newintent) を呼び出したいのですが、ページが変わりません。この私のコード:

public class MainActivity extends Activity {
private TextView IdPeserta, Password;
//private ArrayList<NameValuePair> authentication;
@SuppressWarnings("unused")
//private String temp, _nama = "";
//private readURL rL;

public static String username = "";
public static String password = "";
public static String status = "FALSE";

public void setPassword(String password){
    MainActivity.password = password;
}

public void setUsername(String username){
    MainActivity.username = username;
}

public void setStatus(String status){
    MainActivity.status = status;
}

/** Called when the activity is first created. */
@Override
public 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.main);
    IdPeserta = (TextView) findViewById(R.id.idPeserta);
    Password = (TextView) findViewById(R.id.password);
}    

public void Login(View view){
    setUsername(IdPeserta.getText().toString());
    setPassword(Password.getText().toString());
    if((IdPeserta.getText().length() > 0 && Password.getText().length() > 0)){
        RestTask task = new RestTask();
        task.applicationContext = MainActivity.this;
        task.execute();
    }else{
        Toast.makeText(this,"fill Id Peserta and Password 1", 0).show();
    }
}

public void authenticate(){
    if(status.equals("TRUE")){
        Intent i = new Intent(MainActivity.this, Home.class);
        //PendingIntent pending = PendingIntent.getActivity(this, 0, i, 0);
        startActivity(i);
        finish();
    }else if(status.equals("FALSE")){
        Log.d("gagal", "coba lagi");
    }
}

public static String getService() {

    String responseString = null;

    String baseurlString = "http://10.0.2.2:8080/UjianServices/authentikasi.php";

    RestClient client = new RestClient(baseurlString);
    client.AddParam("id_peserta", MainActivity.username);
    client.AddParam("password", MainActivity.password);

    try {
        client.Execute(RequestMethod.POST);
    } catch (Exception e) {
        Log.d("error", e.getMessage());
        //e.printStackTrace();
    }

    responseString = client.getResponse();

    return responseString;
}

public class RestTask extends  AsyncTask<Object, Object, Object>{
    private ProgressDialog dialog;
    protected Context applicationContext;

    @Override
    protected void onPreExecute() {
        this.dialog = ProgressDialog.show(applicationContext, "Calling", "Time Service...", true);
    }

    @Override
    protected void onPostExecute(Object result) {
        this.dialog.cancel();
        String status = result.toString();
        setStatus(status);
        authenticate();
    }

    @Override
    protected Object doInBackground(Object... arg0) {
        return MainActivity.getService();
    }
}

}

RestTask を使用しなかった場合、ページを変更できます。アクティビティを変更するにはどうすればよいですか?

4

1 に答える 1

0

applicationContextは null であるため、 from を表示するために使用する前に初期化してapplicationContextいません。ProgressDialogonPreExecute

applicationContextProgressDialog を表示するために使用する前に初期化するか、次のように使用する必要がありますMainActivity.this

   @Override
    protected void onPreExecute() {
        applicationContext=MainActivity.this; //<<< initialize context here
        this.dialog = ProgressDialog.show(applicationContext, 
                                 "Calling", "Time Service...", true);
    }
于 2013-01-24T15:56:35.170 に答える