[Android-development] start Activity with Result - crash from JNI

coroberti . coroberti at gmail.com
Fri Nov 24 14:14:30 CET 2017


Dear Ekke,
I'm also doing lots of JNI but with a preference to JNI without Qt.

Your point about calling resolveActivity() at least once before actual call
to an implicit Intent,
is helpful for me and prevents a potential bug in my app.

Thank you posting your findings.

Kind regards,
Robert

On Fri, Nov 24, 2017 at 3:08 PM, ekke <ekke at ekkes-corner.org> wrote:

> I overlooked that this is a built-in-feature from Android.
> From docs:
>
> *Caution:* It's possible that a user won't have *any* apps that handle
> the implicit intent you send to startActivity()
> <https://developer.android.com/reference/android/content/Context.html#startActivity%28android.content.Intent%29>.
> Or, an app may be inaccessible because of profile restrictions or settings
> put into place by an administrator. If that happens, the call fails and
> your app crashes.
>
> so I have to call resolveActivity() before starting the Activity
>
> now all works well :)
>
> ekke
>
> Am 24.11.17 um 12:07 schrieb ekke:
>
> I'm working on an example APP HowTo open files from inside your app in
> other APPs on Android / iOS.
>
> Starting an Activity with QAndroidActivityResultReceiver:
>
> QtAndroid::startActivity(jniIntent, requestId, this);
>
>
> works well and result comes back into
>
> handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data)
>
>
> This works well if there's an app for the Action (ACTION_VIEW,
> ACTION_EDIT, ACTION_SEND) and the MimeType,
> If there's no other APP found - per example ACTION_EDIT and
> application/pdf and you don't have a PDF Editor,
> then I'm getting my requestCode, the resultCode (0 == canceled) - so
> result was sent correct to handleActivityResult()
> but the APP crashes, because it seems there's no Activity created, but
> JNI tries to resume
>
> JNI DETECTED ERROR IN APPLICATION: JNI GetStaticMethodID called with pending exception android.content.ActivityNotFoundException: No Activity found to handle Intent
>
> ...
>
> at void android.app.Instrumentation.checkStartActivityResult(int, java.lang.Object) (Instrumentation.java:1830)
>
> art/runtime/java_vm_ext.cc:410]   at android.app.Instrumentation$ActivityResult android.app.Instrumentation.execStartActivity(android.content.Context, android.os.IBinder, android.os.IBinder, android.app.Activity, android.content.Intent, int, android.os.Bundle) (Instrumentation.java:1539)
>
> art/runtime/java_vm_ext.cc:410]   at void android.app.Activity.startActivityForResult(android.content.Intent, int, android.os.Bundle) (Activity.java:4115)
>
> art/runtime/java_vm_ext.cc:410]   at void android.app.Activity.startActivityForResult(android.content.Intent, int) (Activity.java:4076)
>
> art/runtime/java_vm_ext.cc:410]
>
> art/runtime/java_vm_ext.cc:410]     in call to GetStaticMethodID
>
> art/runtime/java_vm_ext.cc:410] "QtThread" prio=5 tid=11 Runnable
>
> art/runtime/java_vm_ext.cc:410]   | group="main" sCount=0 dsCount=0 obj=0x1330d0a0 self=0x54523f0
>
> art/runtime/java_vm_ext.cc:410]   | sysTid=26897 nice=0 cgrp=default sched=0/0 handle=0xc9b83df0
>
> art/runtime/java_vm_ext.cc:410]   | state=R schedstat=( 0 0 0 ) utm=174 stm=11 core=5 HZ=100
>
> art/runtime/java_vm_ext.cc:410]   | stack=0xc9a87000-0xc9a89000 stackSize=1015KB
>
> art/runtime/java_vm_ext.cc:410]   | held mutexes= "mutator lock"(shared held)
>
> ...
>
>
> Is there a way to avoid the crash and to catch the JNI ERROR ?
>
>
> thx
>
> ekke
>
> _______________________________________________
> Android-development mailing listAndroid-development at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/android-development
>
>
>
> _______________________________________________
> Android-development mailing list
> Android-development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/android-development
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/android-development/attachments/20171124/7617ffbb/attachment.html>


More information about the Android-development mailing list