BaseFragmentActivityApi16.startActivityForResult(intent, int, Bundle) throwing error when targeting Android O-ThrowExceptions

Exception or error:

I started targeting android O in my project I get an error when calling startActivityForResult(intent, int, Bundle) with the error saying it can only be called from group id


compile ''
compile ''
compile ''
How to solve:

It’s a bit late but I’ve found a workaround.
I tried ActivityCompat.startActivityForResult(Activity, intent, int, Bundle); and the warning is gone!



As per this link, this is a bug.
For a workaround, Add this comment above the line of code which gives the warning:

//noinspection RestrictedApi

Old Ans:

I hope you are not importing wrong library. Fragment support library supports fragment for devices running versions prior to Android3.0.

As per this post in SO

Also remember to use Activity if you are using;
use FragmentActivity if you are using
Never attach a to an,
as this will cause an exception to be thrown. is different than

The support library one is annotated @RestrictTo(LIBRARY_GROUP), and also @hide – it’s not meant to be a public API.


Use this in build.gridle

android {
lintOptions {
disable ‘RestrictedApi’

caution: Using this may hide other errors in your project. It will suppresses all errors of this type.

Leave a Reply

Your email address will not be published. Required fields are marked *