繁体   English   中英

从 android 手机模块启动应用程序活动

[英]Start app activity from android phone module

我的应用程序中有 2 个模块:app 模块(它是原始模块)和一个包含活动的第二个模块。

我想在单击按钮时启动位于我的第二个模块中的主要活动,并在单击另一个按钮时返回到我的应用程序模块的主要活动。 项目架构

我尝试执行以下操作,但遇到 ClassNotFoundException:

packageManager.getLaunchIntentForPackage("com.example.secondmodule")?.let {
    startActivity(intent)
}

然后:

val intent = Intent(this, Class.forName("com.example.secondmodule.MainActivity"))
        startActivity(intent)

然后:

startActivity(Intent("com.example.secondmodule"))

但似乎没有任何效果,甚至可能吗? 我该怎么做才能获得这种行为?

这样做

    // Get an instance of PackageManager
    val pm = applicationContext.packageManager

    // Initialize a new Intent
    val intent:Intent? = pm.getLaunchIntentForPackage(packageName)

    // Add category to intent
    intent?.addCategory(Intent.CATEGORY_LAUNCHER)

   // If intent is not null then launch the app
   if(intent != null) {
     applicationContext.startActivity(intent)
   }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM