从.aar库调用Android活动时出错. [英] Error calling Android activity from .aar library.

查看:194
本文介绍了从.aar库调用Android活动时出错.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Google Maps API的项目,该项目执行地理围栏和其他与地图相关的活动.我将此项目转换为一个库(.aar),以便可以与具有类似用例的地图和geofnece的其他项目共享该库.

I have a project that uses googles map api that performs geofencing and other map related activities. I transformed this project into a library (.aar) so I can share it to other projects that has similar use cases with maps and geofnece.

我的问题是当我创建一个新项目并导入.aar库时,我无法在.aar库中调用活动.
单击按钮从库中调用活动后,应用程序崩溃,并在调试器中显示错误.

My problem is when I create a new project and import the .aar library I cannot call activities inside the .aar library.
The app crashers after I click the button to call the activity from the library and shows an error in the debugger.

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.package.name.MapsActivity }

这就是我所说的活动

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);        
    }

    //onclick button
    public void testSubmit(View view) {

        //com.package.name.MapActivity is the activity inside the .aar
        Intent intent = new Intent("com.package.name.MapsActivity");
        startActivity(intent);
    }
}

在导入.aar之后,我还将活动添加到了项目清单中.

I also added the activity into my projects manifest after I imported the .aar

<activity android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <activity android:name="com.package.name.MapsActivity" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

推荐答案

尝试一下:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//com.package.name, 
                                     "classname//com.package.name.MapsActivity"));
startActivity(intent);

从这里回答 https://stackoverflow.com/a/9822278/4848308

这篇关于从.aar库调用Android活动时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆