0

为什么toast显示我的消息?我的CEVAP_SORGULA变量等于 322,但我的意图请求代码是 332

private final static int CEVAP_SORGULA = 322;
public void degistirActivity(final View view){
    startActivityForResult(new Intent(this,veriTopla.class),332);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if (resultCode == Activity.RESULT_OK && requestCode == CEVAP_SORGULA ){
        Toast.makeText(this, "Cevabin: " + data.getExtras().getInt("Cevap"),Toast.LENGTH_LONG).show();
    }
    super.onActivityResult(requestCode, resultCode, data);
}
4

2 回答 2

3

我清楚地看到CEVAP_SORGULA和通过 传递的值之间存在类型错误startActivityForResult。要修复它,请提供变量而不是硬编码的WRONG值。

startActivityForResult(new Intent(this,veriTopla.class),CEVAP_SORGULA);
于 2013-08-21T11:45:52.090 回答
2

你可以试试

Intent i = new Intent(this, SecondActivity.class);
startActivityForResult(i, 332);

默认方法

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == PICK_CONTACT_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            // The user picked a contact.
            // The Intent's data Uri identifies which contact was selected.

            // Do something with the contact here (bigger example below)
        }
    }
}

从 Android 开发者网站查看此示例,为您提供帮助

 public class MyActivity extends Activity {
     ...

     static final int PICK_CONTACT_REQUEST = 0;

     protected boolean onKeyDown(int keyCode, KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
             // When the user center presses, let them pick a contact.
             startActivityForResult(
                 new Intent(Intent.ACTION_PICK,
                 new Uri("content://contacts")),
                 PICK_CONTACT_REQUEST);
            return true;
         }
         return false;
     }

     protected void onActivityResult(int requestCode, int resultCode,
             Intent data) {
         if (requestCode == PICK_CONTACT_REQUEST) {
             if (resultCode == RESULT_OK) {
                 // A contact was picked.  Here we will just display it
                 // to the user.
                 startActivity(new Intent(Intent.ACTION_VIEW, data));
             }
         }
     }
 }
于 2013-08-21T11:43:18.407 回答