OnActivityResult not called if not requesting permissions












0














My app is starting an activity from another package with startActivityForResult. I observed problems when my launching activity gets recreated and saw that onActivityResult is not called in that case after the started activity returns. (It is called correctly if I do not trigger activity recreation.)



These are the steps I performed:




  • Start my activity

  • Click my button which calls startActivityForResult on the ykDroid app

  • Bring my app to background. This causes my activity to be destroyed as I have enabled this in the Android developer settings

  • Bring my app back to foreground (I see OnCreate is called)

  • Swipe a Yubikey NEO which causes the other activity to return.

  • Watch logcat to see that OnActivityResult is not called.


I found out that if I call RequestPermissions for Permission.UseFingerprint I get the OnActivityResult callback even after activity recreation. I don't have a clue why. Can anybody explain this behavior?
Could it be related to ykDroid? see https://github.com/pp3345/ykDroid for their source code.



Here is what I used for testing (Xamarin Android):



[Activity(Label = "@string/app_name", Theme = "@style/MyTheme")]
public class DatabaseSettingsActivity : Activity
{

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.yubichall_test);

FindViewById<Button>(Resource.Id.btn_yubichall).Click += (sender, args) =>
{

byte challenge64 = new byte[64];
for (int i = 0; i < 64; i++)
{
challenge64[i] = (byte) i;


}
var chalIntent = TryGetYubichallengeIntentOrPrompt(challenge64, true);

StartActivityForResult(chalIntent, 123);

};


//Uncomment this and it will work
/* if ((int)Build.VERSION.SdkInt >= 23)
RequestPermissions(new { Manifest.Permission.UseFingerprint }, 99);*/
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Kp2aLog.Log("OnActivityResult: " + requestCode);
if (resultCode == Result.Ok)
{
byte challengeResponse = data.GetByteArrayExtra("response");
if ((challengeResponse != null) && (challengeResponse.Length > 0))
{
FindViewById<TextView>(Resource.Id.text_result).Text =
MemUtil.ByteArrayToHexString(challengeResponse);

}
}
}


public Intent TryGetYubichallengeIntentOrPrompt(byte challenge, bool promptToInstall)
{
Intent chalIntent = new Intent("net.pp3345.ykdroid.intent.action.CHALLENGE_RESPONSE");
chalIntent.PutExtra("challenge", challenge);

IList<ResolveInfo> activities = PackageManager.QueryIntentActivities(chalIntent, 0);
bool isIntentSafe = activities.Count > 0;
if (isIntentSafe)
{
return chalIntent;
}
if (promptToInstall)
{
//please install https://play.google.com/store/apps/details?id=net.pp3345.ykdroid&hl=en
}
return null;
}
}


where the layout yubicall_test is



    <?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_yubichall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yubi challenge"
/>

<TextView
android:id="@+id/text_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>









share|improve this question






















  • If that fixes your issue than why not request permission anyway you have to have runtime permissions in your app!
    – G.hakim
    Nov 21 at 6:29










  • because 1.) not everybody has API Level >= 23 2.) it doesn't make sense to request fingerprint permissions if I don't need them 3.) I don't think this will actually solve the problem on all devices 4.) I don't like fixes I do not understand.
    – Philipp
    Nov 24 at 7:38
















0














My app is starting an activity from another package with startActivityForResult. I observed problems when my launching activity gets recreated and saw that onActivityResult is not called in that case after the started activity returns. (It is called correctly if I do not trigger activity recreation.)



These are the steps I performed:




  • Start my activity

  • Click my button which calls startActivityForResult on the ykDroid app

  • Bring my app to background. This causes my activity to be destroyed as I have enabled this in the Android developer settings

  • Bring my app back to foreground (I see OnCreate is called)

  • Swipe a Yubikey NEO which causes the other activity to return.

  • Watch logcat to see that OnActivityResult is not called.


I found out that if I call RequestPermissions for Permission.UseFingerprint I get the OnActivityResult callback even after activity recreation. I don't have a clue why. Can anybody explain this behavior?
Could it be related to ykDroid? see https://github.com/pp3345/ykDroid for their source code.



Here is what I used for testing (Xamarin Android):



[Activity(Label = "@string/app_name", Theme = "@style/MyTheme")]
public class DatabaseSettingsActivity : Activity
{

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.yubichall_test);

FindViewById<Button>(Resource.Id.btn_yubichall).Click += (sender, args) =>
{

byte challenge64 = new byte[64];
for (int i = 0; i < 64; i++)
{
challenge64[i] = (byte) i;


}
var chalIntent = TryGetYubichallengeIntentOrPrompt(challenge64, true);

StartActivityForResult(chalIntent, 123);

};


//Uncomment this and it will work
/* if ((int)Build.VERSION.SdkInt >= 23)
RequestPermissions(new { Manifest.Permission.UseFingerprint }, 99);*/
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Kp2aLog.Log("OnActivityResult: " + requestCode);
if (resultCode == Result.Ok)
{
byte challengeResponse = data.GetByteArrayExtra("response");
if ((challengeResponse != null) && (challengeResponse.Length > 0))
{
FindViewById<TextView>(Resource.Id.text_result).Text =
MemUtil.ByteArrayToHexString(challengeResponse);

}
}
}


public Intent TryGetYubichallengeIntentOrPrompt(byte challenge, bool promptToInstall)
{
Intent chalIntent = new Intent("net.pp3345.ykdroid.intent.action.CHALLENGE_RESPONSE");
chalIntent.PutExtra("challenge", challenge);

IList<ResolveInfo> activities = PackageManager.QueryIntentActivities(chalIntent, 0);
bool isIntentSafe = activities.Count > 0;
if (isIntentSafe)
{
return chalIntent;
}
if (promptToInstall)
{
//please install https://play.google.com/store/apps/details?id=net.pp3345.ykdroid&hl=en
}
return null;
}
}


where the layout yubicall_test is



    <?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_yubichall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yubi challenge"
/>

<TextView
android:id="@+id/text_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>









share|improve this question






















  • If that fixes your issue than why not request permission anyway you have to have runtime permissions in your app!
    – G.hakim
    Nov 21 at 6:29










  • because 1.) not everybody has API Level >= 23 2.) it doesn't make sense to request fingerprint permissions if I don't need them 3.) I don't think this will actually solve the problem on all devices 4.) I don't like fixes I do not understand.
    – Philipp
    Nov 24 at 7:38














0












0








0







My app is starting an activity from another package with startActivityForResult. I observed problems when my launching activity gets recreated and saw that onActivityResult is not called in that case after the started activity returns. (It is called correctly if I do not trigger activity recreation.)



These are the steps I performed:




  • Start my activity

  • Click my button which calls startActivityForResult on the ykDroid app

  • Bring my app to background. This causes my activity to be destroyed as I have enabled this in the Android developer settings

  • Bring my app back to foreground (I see OnCreate is called)

  • Swipe a Yubikey NEO which causes the other activity to return.

  • Watch logcat to see that OnActivityResult is not called.


I found out that if I call RequestPermissions for Permission.UseFingerprint I get the OnActivityResult callback even after activity recreation. I don't have a clue why. Can anybody explain this behavior?
Could it be related to ykDroid? see https://github.com/pp3345/ykDroid for their source code.



Here is what I used for testing (Xamarin Android):



[Activity(Label = "@string/app_name", Theme = "@style/MyTheme")]
public class DatabaseSettingsActivity : Activity
{

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.yubichall_test);

FindViewById<Button>(Resource.Id.btn_yubichall).Click += (sender, args) =>
{

byte challenge64 = new byte[64];
for (int i = 0; i < 64; i++)
{
challenge64[i] = (byte) i;


}
var chalIntent = TryGetYubichallengeIntentOrPrompt(challenge64, true);

StartActivityForResult(chalIntent, 123);

};


//Uncomment this and it will work
/* if ((int)Build.VERSION.SdkInt >= 23)
RequestPermissions(new { Manifest.Permission.UseFingerprint }, 99);*/
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Kp2aLog.Log("OnActivityResult: " + requestCode);
if (resultCode == Result.Ok)
{
byte challengeResponse = data.GetByteArrayExtra("response");
if ((challengeResponse != null) && (challengeResponse.Length > 0))
{
FindViewById<TextView>(Resource.Id.text_result).Text =
MemUtil.ByteArrayToHexString(challengeResponse);

}
}
}


public Intent TryGetYubichallengeIntentOrPrompt(byte challenge, bool promptToInstall)
{
Intent chalIntent = new Intent("net.pp3345.ykdroid.intent.action.CHALLENGE_RESPONSE");
chalIntent.PutExtra("challenge", challenge);

IList<ResolveInfo> activities = PackageManager.QueryIntentActivities(chalIntent, 0);
bool isIntentSafe = activities.Count > 0;
if (isIntentSafe)
{
return chalIntent;
}
if (promptToInstall)
{
//please install https://play.google.com/store/apps/details?id=net.pp3345.ykdroid&hl=en
}
return null;
}
}


where the layout yubicall_test is



    <?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_yubichall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yubi challenge"
/>

<TextView
android:id="@+id/text_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>









share|improve this question













My app is starting an activity from another package with startActivityForResult. I observed problems when my launching activity gets recreated and saw that onActivityResult is not called in that case after the started activity returns. (It is called correctly if I do not trigger activity recreation.)



These are the steps I performed:




  • Start my activity

  • Click my button which calls startActivityForResult on the ykDroid app

  • Bring my app to background. This causes my activity to be destroyed as I have enabled this in the Android developer settings

  • Bring my app back to foreground (I see OnCreate is called)

  • Swipe a Yubikey NEO which causes the other activity to return.

  • Watch logcat to see that OnActivityResult is not called.


I found out that if I call RequestPermissions for Permission.UseFingerprint I get the OnActivityResult callback even after activity recreation. I don't have a clue why. Can anybody explain this behavior?
Could it be related to ykDroid? see https://github.com/pp3345/ykDroid for their source code.



Here is what I used for testing (Xamarin Android):



[Activity(Label = "@string/app_name", Theme = "@style/MyTheme")]
public class DatabaseSettingsActivity : Activity
{

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.yubichall_test);

FindViewById<Button>(Resource.Id.btn_yubichall).Click += (sender, args) =>
{

byte challenge64 = new byte[64];
for (int i = 0; i < 64; i++)
{
challenge64[i] = (byte) i;


}
var chalIntent = TryGetYubichallengeIntentOrPrompt(challenge64, true);

StartActivityForResult(chalIntent, 123);

};


//Uncomment this and it will work
/* if ((int)Build.VERSION.SdkInt >= 23)
RequestPermissions(new { Manifest.Permission.UseFingerprint }, 99);*/
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Kp2aLog.Log("OnActivityResult: " + requestCode);
if (resultCode == Result.Ok)
{
byte challengeResponse = data.GetByteArrayExtra("response");
if ((challengeResponse != null) && (challengeResponse.Length > 0))
{
FindViewById<TextView>(Resource.Id.text_result).Text =
MemUtil.ByteArrayToHexString(challengeResponse);

}
}
}


public Intent TryGetYubichallengeIntentOrPrompt(byte challenge, bool promptToInstall)
{
Intent chalIntent = new Intent("net.pp3345.ykdroid.intent.action.CHALLENGE_RESPONSE");
chalIntent.PutExtra("challenge", challenge);

IList<ResolveInfo> activities = PackageManager.QueryIntentActivities(chalIntent, 0);
bool isIntentSafe = activities.Count > 0;
if (isIntentSafe)
{
return chalIntent;
}
if (promptToInstall)
{
//please install https://play.google.com/store/apps/details?id=net.pp3345.ykdroid&hl=en
}
return null;
}
}


where the layout yubicall_test is



    <?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_yubichall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yubi challenge"
/>

<TextView
android:id="@+id/text_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>






android xamarin.android android-lifecycle






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 3:15









Philipp

7,012444101




7,012444101












  • If that fixes your issue than why not request permission anyway you have to have runtime permissions in your app!
    – G.hakim
    Nov 21 at 6:29










  • because 1.) not everybody has API Level >= 23 2.) it doesn't make sense to request fingerprint permissions if I don't need them 3.) I don't think this will actually solve the problem on all devices 4.) I don't like fixes I do not understand.
    – Philipp
    Nov 24 at 7:38


















  • If that fixes your issue than why not request permission anyway you have to have runtime permissions in your app!
    – G.hakim
    Nov 21 at 6:29










  • because 1.) not everybody has API Level >= 23 2.) it doesn't make sense to request fingerprint permissions if I don't need them 3.) I don't think this will actually solve the problem on all devices 4.) I don't like fixes I do not understand.
    – Philipp
    Nov 24 at 7:38
















If that fixes your issue than why not request permission anyway you have to have runtime permissions in your app!
– G.hakim
Nov 21 at 6:29




If that fixes your issue than why not request permission anyway you have to have runtime permissions in your app!
– G.hakim
Nov 21 at 6:29












because 1.) not everybody has API Level >= 23 2.) it doesn't make sense to request fingerprint permissions if I don't need them 3.) I don't think this will actually solve the problem on all devices 4.) I don't like fixes I do not understand.
– Philipp
Nov 24 at 7:38




because 1.) not everybody has API Level >= 23 2.) it doesn't make sense to request fingerprint permissions if I don't need them 3.) I don't think this will actually solve the problem on all devices 4.) I don't like fixes I do not understand.
– Philipp
Nov 24 at 7:38

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404781%2fonactivityresult-not-called-if-not-requesting-permissions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404781%2fonactivityresult-not-called-if-not-requesting-permissions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'