我遇到了问题。
在“A”类中我有代码:
Intent cInt = new Intent(Add_Product_Page.this, CategoryListActivity.class); Bundle extra = new Bundle(); extra.putBoolean("for_result", true); startActivityForResult(cInt, GET_CATEGORY, extra);此代码来自另一个启动活动的类
Bundle extra = getIntent().getExtras(); if (extra != null) { isforResult = cInt.getBooleanExtra("for_result", true); setIsforResult(isforResult); } else { setIsforResult(false); } getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Category"); }我调试了A类 ,我得到了额外的值为true但是当我调试另一个类时,我在额外的时候得到NULL
有谁能够帮助我。
提前致谢
I'm having a problems.
In a class "A" I have the code:
Intent cInt = new Intent(Add_Product_Page.this, CategoryListActivity.class); Bundle extra = new Bundle(); extra.putBoolean("for_result", true); startActivityForResult(cInt, GET_CATEGORY, extra);This code is from another class that starts the activity
Bundle extra = getIntent().getExtras(); if (extra != null) { isforResult = cInt.getBooleanExtra("for_result", true); setIsforResult(isforResult); } else { setIsforResult(false); } getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("Category"); }I debugged Class A and I got the value of extra as true but when I am debugged another class I am getting NULL in the extra
Can anybody help me.
Thanks in advance
最满意答案
startActivityForResult()的第三个参数( Bundle option )不是“额外”包。 有关详细信息,请参阅Context#startActivity(Intent,Bundle) 。 那是启动配置。
使用Intent#putExtra(String, boolean)作为布尔额外内容。
Intent intent = new Intent(Add_Product_Page.this, CategoryListActivity.class); intent.putExtra("for_result", true); startActivityForResult(intent, GET_CATEGORY);然后
boolean b = getIntent().getBooleanExtra("for_result", false);这相当于
boolean b = getIntent().getExtras().getBoolean("for_result");您还可以检查intent是否有额外的参数:
intent.hasExtra("for_result");startActivityForResult()'s 3rd argument(Bundle option) is not "extra" bundles. See Context#startActivity(Intent, Bundle) for detail. That is launch configuration.
use Intent#putExtra(String, boolean) for boolean extras.
Intent intent = new Intent(Add_Product_Page.this, CategoryListActivity.class); intent.putExtra("for_result", true); startActivityForResult(intent, GET_CATEGORY);then
boolean b = getIntent().getBooleanExtra("for_result", false);This is equivalant to
boolean b = getIntent().getExtras().getBoolean("for_result");Also you can check intent has extra parameter or not:
intent.hasExtra("for_result");更多推荐
发布评论