How to pass a parameter of type byte [] to the AsyncTask function?

How to pass a parameter of type byte [] to the doInBackground function of the AsynTask class?

When I do something like this:

private class Banana extends AsyncTask<byte[], Void, Void> { protected void doInBackground(byte[]... data) { mCamera.addCallbackBuffer(byte[] data); } protected void onProgressUpdate() { } protected void onPostExecute() { } } 

I get an error saying that the return type is not compatible with the Async Task for the doInBackground function.

+4
source share
1 answer

doInBackground actually expects an array[] . So you can use:

 private class Banana extends AsyncTask<byte[], Void, Void> { protected Void doInBackground(byte[]... data) { mCamera.addCallbackBuffer(data[0]); return null; } protected void onProgressUpdate() { } protected void onPostExecute() { } } 

or you can send this array as a parameter to the constructor of the class:

 private class Banana extends AsyncTask<Void, Void, Void> { private byte[] data; public Banana(byte[] data) { this.data = data; } protected Void doInBackground(Void... data) { mCamera.addCallbackBuffer(this.data); return null; } protected void onProgressUpdate() { } protected void onPostExecute() { } } 
+4
source

Source: https://habr.com/ru/post/1493200/


All Articles