我做過登錄使用Facebook帳戶,通過導入Facebook sdk
作爲庫在我的Android應用程序,但主要問題是我想要去另一個活動,當我用Facebook帳戶登錄我我不瞭解如何做到這一點。如何使用Facebook帳戶登錄後進入nextactivity
LoginActivity.java:
public class LoginActivity extends FragmentActivity {
private ProgressDialog pDialog;
Button btn_login,bnt_Register ;
EditText edt_email,edt_password;
JSONParser jsonParser = new JSONParser();
private static String url_create_product = "http://192.168.1.6/laravel/public/user";
private static final String TAG_SUCCESS = "success";
//private static final String TAG_PORTFOLIOS = "lists";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
bnt_Register=(Button)findViewById(R.id.btnRegister);
btn_login =(Button)findViewById(R.id.btnLogin);
edt_email = (EditText)findViewById(R.id.loginEmail);
edt_password=(EditText)findViewById(R.id.loginPassword);
bnt_Register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in = new Intent(LoginActivity.this,AccountRegister.class);
startActivity(in);
}
});
btn_login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new EmailPassword().execute();
}
});
}
class EmailPassword extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String email =edt_email.getText().toString();
String password =edt_password.getText().toString();
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("email", email));
params1.add(new BasicNameValuePair("password", password));
try{
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", params1);
Log.d("Create Response", json.toString());
return json.toString();
}catch(Exception e){}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
try {
JSONObject json = new JSONObject(file_url);
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
startActivity(i);
//Toast.makeText(getApplicationContext(),"Login", Toast.LENGTH_LONG).show();
// closing this screen
//finish();
} else {
// failed to create product
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
@Override
protected void onResume() {
super.onResume();
// Logs 'install' and 'app activate' App Events.
AppEventsLogger.activateApp(this);
}
@Override
protected void onPause() {
super.onPause();
// Logs 'app deactivate' App Event.
AppEventsLogger.deactivateApp(this);
}
}
我更新您的代碼有問題,請檢查一下。 – 2014-12-08 06:29:46