On Android API 22 when I try to call getBoolean on android.support.v4.app.Fragment's arguments it results in a compile time error. However if I get Arguments in a variable first, it works as it's supposed to. Any idea what am I missing?
Asked
Active
Viewed 1,103 times
1 Answers
4
Those methods were moved to BaseBundle
, from which Bundle
inherits. You can call getBoolean()
and setBoolean()
on a Bundle
just as you did before.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
Ah I see. but Fragment.getArguments() returns a Bundle and if I call Fragment.getArguments().getBoolean(MAP_POSITIONED) it results in an error. – martinpelant Mar 18 '15 at 12:24
-
@martinpelant: If you are encountering a runtime error, use LogCat and examine the Java stack trace: http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this If you are encountering a compile-time error, please edit your question and explain exactly what the error message is. – CommonsWare Mar 18 '15 at 12:26
-
@martinpelant: Hmmm... I cannot reproduce the problem with a regular `android.app.Fragment`. `getArguments().getBoolean("foo")` compiles fine with `compileSdkVersion 22`, where I have that code in `onCreate()` of a `BlankFragment` created by the new-fragment wizard. You might try cleaning your project (Build > Clean Project from the Android Studio main menu) and see if that helps. Otherwise, it's possible this is somehow tied to the specific fragment class that you are using, though I can't quite see how. – CommonsWare Mar 18 '15 at 12:38
-
Cleaning build didn't help. It's tied to android.support.v4.app.Fragment – martinpelant Mar 18 '15 at 12:46
-
@martinpelant: I just changed my test project's fragment to inherit from `android.support.v4.app.Fragment`, and I still get no compile errors from `getArguments().getBoolean("foo")`. If you can create a sample project that can reproduce the error that you can publish somewhere, I would be interested in taking a look at it. – CommonsWare Mar 18 '15 at 12:48
-
Interesting. I wasn't able to reproduce this problem in the new project. The project that causes this error has a lot of modules and dependencies between them. I've checked and every one of the modules has compile api set to 22 and every support dependency is also of version 22. It looks like it's an Android studio bug after all beacuse it compiles fine with a command line – martinpelant Mar 18 '15 at 13:04
-
@martinpelant: This has the feel of the `getClass()` bug that exists (used to exist?) in Android Studio: https://code.google.com/p/android/issues/detail?id=70135 However, I would expect the behavior to be consistent, not vary from project to project. – CommonsWare Mar 18 '15 at 13:19