HBiSoft / HBRecorder

Lightweight screen recording Android library
MIT License
402 stars 137 forks source link

Fix: Null Pointer Exception #129

Closed sofronovicnikola closed 1 year ago

sofronovicnikola commented 2 years ago

Fixes #127

Issue is reproducible when service/process is potentially killed by the system and since ScreenRecordingService.onStartCommand() is returning START_STICKY, and if the service is in the started state, system will try to recreate the service. But, it will not retain intent. So, intent will be null in that case and Attempt to invoke virtual method 'long android.content.Intent.getLongExtra(java.lang.String, long)' on a null object reference will occur.

In that case, stopping service is called to avoid any other potential issue.

Also, consider returning START_REDELIVER_INTENT instead of START_STICKY, so Intent is retained after a service restart.

Changes:

Added null check on Intent Stop Service if Intent is null

bomberaya commented 1 year ago

@HBiSoft have you had the chance to look at this?

imoralesIncode commented 1 year ago

Hi, do you have opportunity to include the fix on the library?

HBiSoft commented 1 year ago

My sincerest apologies for the delay in response. I was busy with a big project. I will quickly look at this and merge it if everything looks ok

vivek-mittal commented 1 year ago

Hi, @HBiSoft - Any plans to merge this PR? I am also seeing the following issue frequently - java.lang.RuntimeException: Unable to start service com.hbisoft.hbrecorder.ScreenRecordService@a88bce with null: java.lang.NullPointerException: Attempt to invoke virtual method 'long android.content.Intent.getLongExtra(java.lang.String, long)' on a null object reference

HBiSoft commented 1 year ago

This is now implemented in - https://github.com/HBiSoft/HBRecorder/releases/tag/2.0.6

Thank you for this and apologies for waiting so long to implement this.

HBiSoft commented 1 year ago

Just a note, there was an issue with the previous release caused by updating the dependencies, not sure if you noticed it. I have updated the library again - https://github.com/HBiSoft/HBRecorder/releases/tag/3.0.1