Reputation: 393
I have a android application which is working well on Emulator. But when i tried it on device, its showing some problem like "could not execute method of the activity at" . And below is the logcat report.
FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3640)
at android.view.View.performClick(View.java:4249)
at android.view.View$PerformClick.run(View.java:17764)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
Caused by: java.lang.NoSuchMethodError: android.app.AlarmManager.setExact
at com.example.manju.remainder.service.task.AlarmTask.run(AlarmTask.java:49)
at com.example.manju.remainder.service.ScheduleService.setAlarm(ScheduleService.java:50)
at com.example.manju.remainder.service.ScheduleClient.setAlarmForNotification(ScheduleClient.java:55)
at com.example.manju.remainder.MainActivity.callAlarm(MainActivity.java:507)
at com.example.manju.remainder.MainActivity.checkDates(MainActivity.java:474)
at com.example.manju.remainder.MainActivity.submitButtonClicked(MainActivity.java:160)
Can anyone help me regarding this..
Upvotes: 1
Views: 1029
Reputation: 938
Another solution is , set the minSdkVersion in your build.gradle as the one in your Phone.
Suppose your Phone version is Android 5.0 , then the API Level is 21. You can set the minSdkVersion 21.
defaultConfig {
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
This will definetly work.
Upvotes: 0
Reputation: 2827
Try this:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
// only for kitkat and newer versions
android.app.AlarmManager.setExact(int type, long triggerAtMillis, PendingIntent operation);
} else {
android.app.AlarmManager.set(int type, long triggerAtMillis, PendingIntent operation);
}
Basically, .setExact(...);
method requires API 19 & above (it's just a way to bypass the optimization android provides, for maximizing battery life).
Upvotes: 7