I've a problem with checking is device supports Mutli Window Mode. I'm using this function to check it isInMultiWindowMode()
but it've added in API 24, and when i'm runs my app on device with lower api version it cause an exception. There is any replacement for this function for lower api versions?
Asked
Active
Viewed 1,723 times
2
-
If it doesn't exist in lower API's how can you check it? – Lord Goderick Jan 21 '17 at 08:30
2 Answers
2
There is any replacement for this function for lower api versions?
Not in the Android SDK. There is no multi-window mode (from the Android SDK's standpoint) prior to API Level 23. And, for whatever reason, Google elected not to add isInMultiWindowMode()
to ActivityCompat
, perhaps because they cannot support the corresponding event (onMultiWindowModeChanged()
).
So, here's a free replacement method:
public static boolean isInMultiWindowMode(Activity a) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
return false;
}
return a.isInMultiWindowMode();
}
Add that to some utility class somewhere and call it as needed.
Also note that isInMultiWindowMode()
suffers from a race condition that makes it unreliable, IMHO.

Egis
- 5,081
- 5
- 39
- 61

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
1Multiwindow support and the isInMultiWindowMode() were added in Android N (API 24) – Juanvi Martinez Sep 08 '17 at 13:29
0
What @CommonsWare explained is true, it is a race condition. Hence, isInMultiWindowMode()
will give actual result if you call it from inside post method:
View yourView = findViewById(R.id.yourViewId);
yourView.post(new Runnable() {
@Override
public void run() {
boolean actualResult = isInMultiWindowMode();
}
});

Anggrayudi H
- 14,977
- 11
- 54
- 87