mercredi 19 décembre 2018

Android getDeclaredConstructors() behaving differently for Android 28 (Pie)

I know, this looks like a bad idea but my project has this line here:

val constructor = SQLiteQuery::class.java.declaredConstructors.first()

The class itself has one non public constructor but that is exactly the one I need for further work.

SQLiteQuery(SQLiteDatabase db, String query, CancellationSignal cancellationSignal) {
   super(db, query, null, cancellationSignal);
   mCancellationSignal = cancellationSignal;
}

It works fine when targetSdkVersion 27 is set. However, the moment I set the targetSdkVersion 28 this causes problems on Android 9. The list of constructors is empty (so not even private ones are included).

I can't find any changes in the API / documentation. The source code also still shows the above mentioned constructor.

Question is: Why is this and how can I get the complete list of constructors?





Aucun commentaire:

Enregistrer un commentaire