android – TimePicker getCurrentMinute, getCurrentHour method is deprecated in API 23-ThrowExceptions

Exception or error:

I’m Creating a Alarm based Application with API version 23. But TimePicker getCurrentMinute,getCurrentHour method is Deprecated. Which method will be replace of this method ?

EDIT:

According to google documentation now we have to use getMinute() and getHour() method. But it's only working in api 23. what we have to do for other api?

How to solve:

Just check the Android official docs .. http://developer.android.com/reference/android/widget/TimePicker.html

it tells you everything

public Integer getCurrentMinute ()

Added in API level 1
This method was deprecated in API level 23.
Use getMinute()

Returns
the current minute

and

public Integer getCurrentHour ()

Added in API level 1
This method was deprecated in API level 23.
Use getHour()

Returns
the current hour in the range (0-23)

Android offers runtime checks for API version.
Most of the time in such cases, you’ll want to run cases like

if (Build.VERSION.SDK_INT >= 23 ) 
    myTimePickerView.getHour();
else 
    myTimePickerView.getCurrentHour();

@see http://developer.android.com/reference/android/os/Build.VERSION.html

###

i faced same issue. if you write your code such as
getCurrentHour()*(striked through) it doesnt make an issue

the code runs gets complied and runs saying
“complete build performed and run since…”

since if you use getHour or getMinute you have to put the version.SDK if else statement (which i tried but didnt work at that time for some reason)
and none the less increases code lines and complexity.

Leave a Reply

Your email address will not be published. Required fields are marked *