如何从Android的另一个项目的活动称之为一个项目的活动吗?还有反之亦然?项目、反之亦然、称之为、Android

2023-09-09 21:04:07 作者:月亮也不见了

我在做一个集成项目,其中包括集成了两个项目进入one.How我想做的事情是这样的,我有一个共同的项目,这种共同项目的活动应该能打电话通知其他两个项目的活动,按照像一个特定的按钮preSS不同的事件,我etc.How能做到这一点?有没有可能通过的意图?

I am doing an integration project,which involves integrating two projects into one.How I want to do this is,I have a common project,the activity of this common project should be able to call activities of the other two projects,as per different events like a particular button press,etc.How can I do this?Is it possible through intents?

此外,其他两个项目的活动应该能够调用每个other.How做到这一点?

Also,the activities of the other two projects should be able to call each other.How to do this?

推荐答案

您将不得不使用意图过滤器,下面

You will have to use intent filters, Sample code below

    PackageManager packageManager = getPackageManager();

    Intent baseIntent = new Intent(ACTION_PICK_PLUGIN);
    baseIntent.addCategory("matching.catagory");

    List<ResolveInfo> activities = packageManager.queryIntentActivities(baseIntent, PackageManager.GET_RESOLVED_FILTER);

然后使用以下火的意图,

Then fire intent using the following,

Intent baseIntent = new Intent(activities.get(indexOfChild).filter.getAction(0));
baseIntent.addCategory(activities.get(indexOfChild).filter.getCategory(0));     
baseIntent.setComponent(newComponentName(activities.get(indexOfChild).activityInfo.packageName,activities.get(indexOfChild).activityInfo.name));
startActivity(baseIntent);

我希望它能帮助。

I hope it helps..