Reputation: 437
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?
Upvotes: 2
Views: 1890
Reputation: 1007484
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.
Upvotes: 2
Reputation: 15165
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();
}
});
Upvotes: 0