how to use implicit intent in android

127 Views Asked by At

In my application, I created two activities. In activity1, I created a button, set event: enter image description here

activity2, I created, and write in manifest: enter image description here

when i click to the button in activity1, error was throw: enter image description here

Why? Please explain to me. Thank you

I expect activity2 to run when I click the button

2

There are 2 best solutions below

1
Harshil Thakkar On

I had find issue in your code. Inside Click event of button change as per below. use startActivityForResult() instead of startActivity().

It will works.

0
Khush Parmar On

Use the ACTION_MAIN instead of ACTION_VIEW as below inside your button click listener,

val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_APP_CALENDAR)
startActivity(intent)

You are getting this error because the ACTION_VIEW is related to the generic action like viewing various types of data like if you set the data for any website URL so the system will be capable to open the the browser as it is handling on this basis and in your case system is not able to find the particular intent as type of view for the calendar. While the calendar application is the for the type where we need to specify the entry point as in terms of opening the main screen of the application so that the system will understand to open the main part of the specific application. Whether both are the intent type but for the different category you must need to choose different one.