How to call activity from a library module in android studio

后端 未结 1 1516
刺人心
刺人心 2020-12-10 16:06

I am trying to call an activity from a library module in my application. I keep getting the error

android.content.ActivityNotFoundException: Unable to find exp

相关标签:
1条回答
  • 2020-12-10 16:56

    We can use reflection to get class object.

    Class.forName("com.mypackage.myMainActivity")

    Add this code in Library project to call,

    try {
          Intent myIntent = new Intent(this,Class.forName("com.mypackage.myMainActivity"));
          startActivity(myIntent );
    } catch (ClassNotFoundException e) {
         e.printStackTrace();
    }
    

    "com.mypackage.myMainActivity" is the Activity present in Main project, that we need to call from its Library project.

    0 讨论(0)
提交回复
热议问题