此行抛出空指针异常错误:
String dataPath = intent.getData().toString();
有谁知道为什么?以下是我主要活动的片段。 一切都很好看。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_picker);
Intent intent = getIntent();
String dataPath = intent.getData().toString();
final Uri data = Uri.parse(dataPath+"people/");
final Cursor c = managedQuery(data, null, null, null, null);
String[] from = new String[] {People.NAME};
int[] to = new int[] {R.id.itemTextView };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R. layout.listitemlayout, c, from, to);
ListView lv = (ListView)findViewById(R.id.contactListView);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos,
long id) {
c.moveToPosition(pos);
int rowId = c.getInt(c.getColumnIndexOrThrow("_id"));
Uri outURI = Uri.parse(data.toString() + rowId);
Intent outData = new Intent();
outData.setData(outURI);
setResult(Activity.RESULT_OK, outData);
finish();
}
});
}
答案 0 :(得分:1)
要调用其他活动,我们通常会使用这样的意图:
要发送的第一个活动:
Intent in = new Intent(MainActivity.this, NewActivity.class);
String StrName = "xyz"
in.putExtra("data",StrName);
startActivity (in);
接收另一项活动:
String Sname = getIntent().getExtras().getString("data");
要查看意图的详细信息,请参阅此处:http://developer.android.com/guide/components/intents-filters.html