App crashes while uploading image - android.app.RemoveServiceException: can't deliver broadcast
See original GitHub issueFrom @neddinn on November 28, 2017 7:32
Tell us about the problem
The app crashes when trying to upload an image. Error:
System.err: java.lang.RuntimeException: Error receiving broadcast Intent { act=net.gotev.uploadservice.broadcast.status flg=0x10 (has extras) } in com.tns.gen.net.gotev.uploadservice.UploadServiceBroadcastReceiver_ftns_modules_nativescript-background-http_background-http_l9_c79__@4255a258
System.err: at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:782)
System.err: at android.os.Handler.handleCallback(Handler.java:733)
System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
System.err: at android.os.Looper.loop(Looper.java:146)
System.err: at android.app.ActivityThread.main(ActivityThread.java:5602)
System.err: at java.lang.reflect.Method.invokeNative(Native Method)
System.err: at java.lang.reflect.Method.invoke(Method.java:515)
System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
System.err: at dalvik.system.NativeStart.main(Native Method)
System.err: Caused by: com.tns.NativeScriptException: Cannot find object id for instance=com.tns.gen.net.gotev.uploadservice.UploadServiceBroadcastReceiver_ftns_modules_nativescript-background-http_background-http_l9_c79__@4255a258
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:959)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:953)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:937)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:929)
System.err: at com.tns.gen.net.gotev.uploadservice.UploadServiceBroadcastReceiver_ftns_modules_nativescript-background-http_background-http_l9_c79__.onProgress(net.gotev.uploadservice.UploadServiceBroadcastReceiver.java)
System.err: at net.gotev.uploadservice.UploadServiceBroadcastReceiver.onReceive(UploadServiceBroadcastReceiver.java:40)
System.err: at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:772)
System.err: ... 9 more
ActivityManager: Process org.nativescript.fo3mobilenativescript (pid 27172) (adj 0) has died.
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
I’m using nativescript-background-http v3.0.0 & tns-core-modules v3.3.0
- CLI: 3.3.1
- Cross-platform modules: tns-core-modules v3.3.0
- Runtime(s): tns-android v3.2.0
- Plugin(s): nativescript-background-http v3.0.0
Please tell us how to recreate the issue in as much detail as possible.
This error is quite erratic but it mostly doesn’t work, after taking a photo using camera plugin and saving or even selecting an image from the gallery, when I try to upload, it crashes the application and throws the aforementioned error.
Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.
var camera = require('nativescript-camera');
var fs = require('file-system');
var imageSource = require('image-source');
var bghttp = require('nativescript-background-http');
var session = bghttp.session('image-upload');
camera.takePicture()
.then(function (imageAsset) {
var hash = (new Date()).getTime() + Math.floor(Math.random() * 20);
let folder = fs.knownFolders.documents();
let path = fs.path.join(folder.path, `Test-${hash}.png`);
return imageSource.fromAsset(imageAsset)
.then(function (res) {
res.saveToFile(path, 'png');
var request = {
url: "http://httpbin.org/post",
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": 'randomName'
},
description: "{ 'uploading': " + 'randomName' + " }"
};
var task = session.uploadFile(path, request);
task.on("progress", logEvent);
task.on("error", logEvent);
task.on("complete", logEvent);
function logEvent(e) {
console.log("currentBytes: " + e.currentBytes);
console.log("totalBytes: " + e.totalBytes);
console.log("eventName: " + e.eventName);
}
return {};
});
}).catch(function (err) {
console.log(`Error -> ${err.message}`);
});
Copied from original issue: NativeScript/NativeScript#5098
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
can't deliver broadcast" exception on Samsung Phones ...
The broadcasts are registered in onResume of Activity and unregistered in onPause. As mentioned the crash occurs only after app has been running...
Read more >can't deliver broadcast [245258072] - Visible to Public - Issue ...
In firebase I see crashes only for Android 13 (Only Pixel devices). Our App use this library's
Read more >Issue Trackers and the "Can't Deliver Broadcast" Bug
Fatal Exception: android.app.RemoteServiceException$CannotDeliverBroadcastException: can't deliver broadcast at android.app.ActivityThread.
Read more >Detect and diagnose crashes - Android Developers
Any app component, even components like broadcast receivers or content providers that are running in the background, can cause an app to crash....
Read more >Android app freezing & crashing phone - Bug Reports
Platform : Android version 10 App version number: 1.28.6 (559) Screenshots of what you are seeing: n/a Description of problem: While loading ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lini I ended up getting past this issue by setting the large heap flag in the android manifest.
android:largeHeap="true"
I solved this issue by move some logic outside the onComplete() function. Seem you must create single instruction to lighten the calculations. For example you must save in let or const your JSON.parse(), because as argument the single calculation is too heavy.
My working code: