Error calling Android activity from .aar library.

拈花ヽ惹草 提交于 2019-12-24 16:34:09

问题


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.

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 }

This is how I call the activity

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

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>

回答1:


Try this:

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

Answer from here https://stackoverflow.com/a/9822278/4848308



来源:https://stackoverflow.com/questions/35166606/error-calling-android-activity-from-aar-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!