-1

是什么原因会影响我不加载下一个活动的意图我已经修复了我的清单意图是正确的按钮是好的并且活动很好基本上我没有任何错误或我没有看到任何可以任何人为我清除这些东西我需要帮助..如果你想检查它,这是我的意图

***Home activity***
package com.bpi.gears;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;


public class Home extends Activity {

 ImageButton btn_profile;
 Intent intent;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    btn_profile = (ImageButton)findViewById(R.id.btn_profile);


 final Intent intent = new Intent();
      intent.setClass(Home.this, Profile.class);
      btn_profile.setOnClickListener(new OnClickListener() {
     public void onClick(View v) {
         startActivity(intent);
            }});
        }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;

}
}


 **MainActivity**
package com.bpi.gears;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

Button btn_login;
EditText ID_username;
EditText ID_password;
TextView message;
Intent intent;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainactivity);

    btn_login = (Button) findViewById(R.id.btn_login);
    ID_username = (EditText) findViewById(R.id.ID_username);
    ID_password = (EditText) findViewById(R.id.ID_password);
    message = (TextView) findViewById(R.id.ID_login);


        btn_login.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {

            if("".equals(ID_username.getText().toString()) || "".equals(ID_password.getText().toString())){

                Toast toast = Toast.makeText(MainActivity.this,     "Please type in Username and Password.", Toast.LENGTH_LONG);
                toast.show();

            } else {
                authenticateUser();

            }



        }
    });

}

protected void authenticateUser() {
    (new AuthenticateUserTask(this)).execute();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;

}

private class AuthenticateUserTask extends AsyncTask<Void, Void, Boolean> {

    @SuppressWarnings("unused")
    Context mContext;
    protected boolean willContinue;

    public AuthenticateUserTask(Context context) {
        super();

        mContext = context;

    }

    @Override
    protected Boolean doInBackground(Void... params) {
        .....
 username="+ID_username.getText().toString()+"&password="+ID_password.getText().toString());
        willContinue = false;

        try{

            ....

            Log.d("Response",""+resp);

            if(resp == 200){
                willContinue = true;
                Log.d("doInBackground","Response is true.");
            }
            else {
                willContinue = false;
                Log.d("doInBackground","Response is false from try.");
            }

        } catch (IOException e) {

            e.printStackTrace();
            willContinue = false;
            Log.d("doInBackground","Response is false from catch.");
        }

        return willContinue;


}

          protected void onPostExecute(Boolean willContinue) {

            if(willContinue){
                Log.d("Response From onPostExecute","willContinue is true, starting Home activity.");
                Toast.makeText(getApplicationContext(), "Login Successful.", Toast.LENGTH_LONG).show();


                /*Intent todashboard = new Intent(MainActivity.this,Home.class);
                startActivity(todashboard);
                finish();*/


            btn_login.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            final Intent intent = new Intent(MainActivity.this, Home.class));
        startActivity(intent);
                    }});

                }


                else{
                Log.d("Response From onPostExecute","willContinue is false.");
                Toast.makeText(getApplicationContext(), "Login Failed.",     Toast.LENGTH_LONG).show();

            }

           }



    }

}

4

1 回答 1

0

把你的onClickListener拿出来AsyncTask放在你onCreate()Activity

并改变这个

final Intent intent = new Intent();
intent.setClass(MainActivity.this, Home.class);

final Intent intent = new Intent(MainActivity.this, Home.class));
startActivity(intent);

并将其全部放入您的onClick(). 希望这会有所帮助......让我知道

于 2013-03-20T01:21:09.320 回答