0

不知道标题是否与上下文匹配,但这是我想要做的:当用户单击 button1 时,我在MainActivity上有两个按钮它启动包含所有已安装应用程序列表的Home活动,现在如果用户从列表中选择任何应用程序,如浏览器,它应该返回到 MainActivity。现在,当用户单击 button2 时,它应该打开之前从 Home 活动列表中选择的应用程序(浏览器)。

即使是很少的帮助也将不胜感激。感谢大家。

主要活动:

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

应用信息:

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);
}
}
4

0 回答 0