19

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 com.android.support.

Gradle:

compile 'com.android.support:design:26.0.0'
compile 'com.android.support:cardview-v7:26.0.0'
compile 'com.android.support:support-v13:26.0.0'
Nick Mowen
  • 2,572
  • 2
  • 22
  • 38
  • Sounds like you should [file a bug](https://issuetracker.google.com/issues/new?component=192731&template=842428). – ianhanniballake Jul 25 '17 at 16:08
  • @Nick Mowen are you using support based fragment ..FragmentActivity -Base class for activities that want to use the support-based Fragment and Loader APIs. – Zohra Khan Jul 25 '17 at 16:55
  • @ZohraKhan I am using it on AppCompatActivity inside of a views onClick method – Nick Mowen Jul 25 '17 at 20:13

3 Answers3

19

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

islamdidarmd
  • 725
  • 5
  • 19
5

Edit:

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 android.app.Fragment; use FragmentActivity if you are using android.support.v4.app.Fragment. Never attach a android.support.v4.app.Fragment to an android.app.Activity, as this will cause an exception to be thrown.

android.app.Fragment is different than android.support.v4.app.Fragment.

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

Kishan Donga
  • 2,851
  • 2
  • 23
  • 35
Zohra Khan
  • 5,182
  • 4
  • 25
  • 34
1

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.

Praveen
  • 430
  • 3
  • 11