不知道标题是否与上下文匹配,但这是我正在尝试做的事情:当用户点击button1时,我在 MainActivity 上有两个按钮,它启动主页活动,其中包含已安装的所有应用的列表,现在,如果用户从列表中选择任何应用,则应返回到MainActivity。现在,当用户点击button2时,它应该打开之前从Home活动列表中选择的应用程序(浏览器)。
即使很少的帮助也会受到赞赏。谢谢大家。
MainActivity:
final int APPLIST = 10;
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.button1:
Intent i = new Intent("android.intent.action.DRAWER");
startActivityForResult(i,APPLIST);
break;
case R.id.button2:
// starts an app(selected earlier)
break;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == APPLIST) {
if (resultCode == Activity.RESULT_OK) {
// don't know what to get (may be app item position)
}
}
}
家庭活动:
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// for starting selected app
// ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
// startActivity(app.intent);
//instead of starting app from here, I want to put data in extra something like that & returns with data back to MainActivity
ApplicationInfo:
class ApplicationInfo {
CharSequence title;
Intent intent;
Drawable icon;
boolean filtered;
final void setActivity(ComponentName className, int launchFlags) {
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(className);
intent.setFlags(launchFlags);
}
}