ban-geoengineering ban-geoengineering - 3 months ago 110
Android Question

Android Lint warning: "Redundant array creation for calling varargs method"

I am getting the above Lint warning in my Android project for the

new Void[] {}
part of the following code:

new AsyncTask<Void, Void, Exception>() {

@Override
protected void onPreExecute() {
showToast("Restarting NFC...");
}

@Override
protected Exception doInBackground(Void... params) {
try {
disableNfcForegroundDispatch();
Thread.sleep(1000L);
enableNfcForegroundDispatch();
return null;
}
catch (Exception e) {
return e;
}
}

@Override
protected void onPostExecute(Exception e) {
if (e == null) {
showToast("...NFC restarted.");
}
else {
Log.e(LOG_TAG, "Could not restart NFC!", e);
showToast("Could not restart NFC: " + e);
}
}

}.execute(new Void[] {});


I am unable to replace the problematic
new Void[] {}
with
null
, so what is the correct solution?

Answer

Leave the argument list empty:

.execute();