OnActivityResult is not triggering after selecting image from gallery

TirumalTirumal USMember ✭✭

Hi, I have an activity which is inherited by BaseActivity (Followed below Activity) and i am selecting a image from intent after select a image activity OnDestroy is calling and activity is closing and not triggering OnActivityResult.
Can any one help me to solve this problem. Below added my code...

public abstract class BaseActivity : AppCompatActivity
{
public static Activity CurrentActivity { get; set; }
public Toolbar Toolbar
{
get;
set;
}
protected override void OnCreate(Bundle savedInstanceState)
{

        CurrentActivity = this;
        //SetTheme(Resource.Style.Theme_Splash);                
        SetTheme (Settings.AppTheme == AppTheme.Blue ? Resource.Style.MyAppThemeBlue : Resource.Style.MyAppThemeOrange);

        base.OnCreate(savedInstanceState);
        SetContentView(LayoutResource);
        Toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
        if (Toolbar != null)
        {
            SetSupportActionBar(Toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

        }
    }

[Activity(Label = "@string/app_name", ScreenOrientation = ScreenOrientation.Portrait, NoHistory = true, MainLauncher = true, Icon = "@mipmap/icon", LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]

public class MyActivity : BaseActivity
{

protected override int LayoutResource
    {
        get
        {
            return Resource.Layout.activity_welcome;
        }
    }

     internal void GoToSelectImage()
    {
        var intent = new Intent();
        intent.SetType("image/*");
        intent.SetAction(Intent.ActionGetContent);
        StartActivityForResult(intent, 2);
    }


protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
    base.OnActivityResult(requestCode, resultCode, data);   
           if (resultCode == Result.Canceled)
           {
               return;
           }
            if ( resultCode == Result.Ok && requestCode == 1)
            {
                try
                {
                    Java.IO.File file = new Java.IO.File(this.selectedmagePath);    
                    var filePath = file.AbsolutePath;
                    filePath = filePath.Substring(6);
                }
                catch (Exception ex)
                {
            App.Logger.Report(ex);
        }
            }
}
 }
 Thanks in advance.....

Posts

  • fernandopenteadofernandopenteado USMember ✭✭

    Hey
    Did you find any answer for it? I'm having the same trouble...

    Thanks!

  • TerrenceJacksonTerrenceJackson USMember
    edited January 2017

    Hi Guys -

    Having the same problem. Did you guys ever get a solution?

    Thanks!

  • RonaldoddddRonaldodddd MYMember ✭✭

    StartActivityForResult(intent, 2);
    request code is 2,
    but expecting the one with request code which is 1.
    Seriously?

Sign In or Register to comment.