Android - startActivityForResult immediately triggering onActivityResult
You can't use startActivityForResult()
if your activity is being launched as a singleInstance
or singleTask
. standard
or singleTop
launch mode will fix the problem.
startActivityForResult() immediately call OnActivityResult when call another app
I just add launchIntent.setFlags(0);
before startActivityForResult()
based on this answer
onActivityResult called immediately on startActivityForResult
Remove the "New Task" flag from the intent.
startActivityForResult
must be under the same task as the calling activity.
According to documentation:
if the activity you are launching uses
Intent#FLAG_ACTIVITY_NEW_TASK
, it will not run in your task and thus you will immediately receive a cancel result.
Cordova onActivityResult is called immediately after startActivityForResult with RESULT_CANCELED
I faced the same issue in one of my cordova application. I could not find the source of error but I resolved it by creating new project and installing all plugins again. It worked.
startActivityForResult to create pending notification triggering immediately
The way you are setting an alarm is wrong. You are setting an alarm at current system time and that's the reason it gets triggered as you set it.
To set the alarm you are using calendar.getTimeInMillis()
in alarmManager.set()
and you initializes your calendar as,
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
Which is the current time, not the desired time you want to set, and that's why alarm fires as you set it.
To set the alarm at the specific time, first set the desired time
and/or date
in the calendar as,
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2015);
calendar.set(Calendar.MONTH, 3);
calendar.set(Calendar.DAY_OF_MONTH, 18);
and set the alarm as,
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
Which will trigger an alarm on March 18, 2015
i.e. on tomorrow.
Set your desired year, month and day values in calendar.set()
to fire alarm at the time you want.
startActivityForResult for ACTION_APPLICATION_DETAILS_SETTINGS not triggering onActivityResult
If your call to the startActivityForResult
is in a Fragment
, you can use the Fragment
's version of startActivityForResult
. So call
startActivityForResult(i,REQUEST_APP_DETAILS);
instead of
context.startActivityForResult(i,REQUEST_APP_DETAILS);
Then, have your onActivityResult
in the Fragment
as well. If you also have overridden onActivityResult
in your Activity
, don't miss a call to super.onActivityResult(...)
in that.
Related Topics
Generate Signed APK Android Studio
Android Split Action Bar with Action Items on the Top and Bottom
How to Set Cursor Position in Edittext
Android How to Create Runtime Thumbnail
Android Studio: Drawable Folder: How to Put Images for Multiple Dpi
Android View Not Attached to Window Manager
What Are the Differences Between Activity and Fragment
Android: Collapsingtoolbarlayout and Swiperefreshlayout Get Stuck
How to Get Images Dynamically from Drawable Folder
How to Auto-Start an Android Application
Android Studio: Cannot Recover Key
Android: Can Height of Slidingdrawer Be Set with Wrap_Content
Custom Seekbar (Thumb Size, Color and Background)
When to Use a Content Provider
Converting Activity into Fragment