Why specific activity can't start while doing MacroBenchmark in Android?

523 views Asked by At

I have written a benchmark method to get benchmark report on specific activity. My plan is to first do this portion properly. And then adding other operation like clicking on a button and test how frame timing metric works. As I have converted code into MVVM pattern so main goal is to compare with previous code.

Written method:

    @get:Rule
    val benchmarkRule = MacrobenchmarkRule()

    @Test
    fun startupEntryActivity() = benchmarkRule.measureRepeated(
        packageName = "io.demo",
        metrics = listOf(FrameTimingMetric()),
        iterations = 5,
        startupMode = StartupMode.COLD,
    ) {

        pressHome()

        val intent = Intent()
        intent.setPackage("io.demo")
        intent.action = "io.demo.views.splash.SplashIntroSelectionActivity"
        startActivityAndWait(intent)
    }

But its getting error in test. Its leaving me without any clue

Error: Activity not started, unable to resolve Intent { act=io.demo.views.splash.SplashIntroSelectionActivity flg=0x10008000 pkg=io.demo }

Need to know where its getting wrong or am doing it wrong

1

There are 1 answers

0
Himanshu On

I resolved this, I have launched my browsable deeplink activity with below code snippet. You have to set action, category, package and component (Intent.CATEGORY_DEFAULT if not browsable). Hope it will help you.

val intent = Intent().apply {
            action = Intent.ACTION_VIEW
            addCategory(Intent.CATEGORY_BROWSABLE)
            setPackage("<package name>")
            component = ComponentName("<package name>","<package>.activity.XYZActivity")
            data = Uri.parse("https://example.com")
        }
        startActivityAndWait(intent)