java - Register component callbacks appropriate for current SDK version -
java - Register component callbacks appropriate for current SDK version -
i want receive notifications ontrimmemory when available (ics+) , onlowmemory otherwise (> ics). questions following:
will scheme allow me define class implements interface not in current sdk long don't instantiate it? example, definingcallbacksics implements componentcallbacks2
while targeting minsdk 8, example, checking current sdk_int before choosing instantiate , register. will onterminate called when application ready cleaned system? vaguely remember hearing in days of application life cycle methods aren't guaranteed called. from application class:
@suppresslint("newapi") @override public void oncreate() { super.oncreate(); if (build.version.sdk_int >= build.version_codes.ice_cream_sandwich) { callbacksics = new callbacksics(); registercomponentcallbacks(callbacksics); } else { callbackslegacy = new callbackslegacy(); registercomponentcallbacks(callbackslegacy); } } @suppresslint("newapi") @override public void onterminate() { super.onterminate(); if (build.version.sdk_int >= build.version_codes.ice_cream_sandwich) { unregistercomponentcallbacks(callbacksics); } else { unregistercomponentcallbacks(callbackslegacy); } }
java android
Comments
Post a Comment