onActivityResult is not called on when the activity is finished












0















I am an Android newbie and I need to figure out how to return data from one activity to another. The idea is that when a row in a recycler view is clicked, it will load the selected row in another activity. If the row is deleted, then the data row is deleted a list, and the control is returned the activity containing the recycler view. But I am getting the following error.



Process: com.manoflogan.criminalintent, PID: 27222
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid
view holder adapter positionViewHolder{9ed884a position=1 id=-1, oldPos=1,
pLpos:-1 scrap [attachedScrap] tmpDetached no parent}
android.support.v7.widget.RecyclerView{833ff9c VFED..... ......I.
0,0-1080,1584 #7f070032 app:id/crime_recycler_view},
adapter:com.manoflogan.criminalintent.CrimeListFragment$CrimeAdapter@4ad8da5,
layout:android.support.v7.widget.LinearLayoutManager@1abc57a,
context:com.manoflogan.criminalintent.CrimeListActivity@6a147d9
at
android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5715)
at
android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5898)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at
android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at
android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at
android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at
android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at
android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3875)
at
android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
at
android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1877)
at
android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:407)
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:693)
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2018-11-24 22:11:30.588 1608-1608/? E/lowmemorykiller: Error writing /proc/2


This is the workflow




  1. When the app starts, the user will see an empty view asking the user to
    add a new Crime by clicking on + button on the menu. Image # 1. This is the fragment responsible for rendering the home screen.


  2. When + symbol is clicked, then the user is directed to a [different activity which encapsulates a view
    pager that manages a fragment. The user can either click on the back button on the menu bar, or the device back button to see the added entries on the home screen . This is an activity that uses ViewPager to manage multiple Crime objects.


  3. The user can repeat step # 2 to add more *crimes*.



  4. To delete the crime, the user clicks/taps on any view holder (row) to go to the same activity as seen in step # 2, and then taps on the garbage icon. The item is then deleted, and the user is redirected back to the view managed by the parent's activity screen. This the block of code that invokes the activity that encapsulates the selected view.



    private class CrimeHolder extends RecyclerView.ViewHolder implements
    View.OnClickListener {
    // Child views instance variables.


    public CrimeHolder(View view) {
    super(view);
    // *. . . Initialising child views . . . *
    }

    @Override
    public void onClick(View view) {
    Intent intent = CrimePagerActivity.newIntent(getActivity(),
    mCrime.getId());
    lastAdapterClickedPosition = getAdapterPosition();

    // Invoking another activity. I would like the activity result to be handled by `onActivityResult`.
    getActivity().startActivityForResult(intent,
    CRIME_VIEW_CODE);
    }

    void bind(Crime crime) {
    mCrime = crime;
    // Setting the state of child views
    }
    }



When the user clicks the delete button, the following menu option is
triggered,



@Override
public boolean onOptionsItemSelected(MenuItem item) {
CrimeLab crimeLab = CrimeLab.get(getActivity());
Intent intent = new Intent();
switch(item.getItemId()) {
case R.id.delete_crime:
// Idea is that this index will be instantiated when activity result is returned.
intent.putExtra(CrimeListFragment.DELETE_ROW_INDEX,
crimeLab.getCrimes().indexOf(mCrime));
crimeLab.deleteCrime(mCrime);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}


Here are what I think are my issues.





  1. Ideally, when I have set my result, and have invoked finish to return to the previous activity, I would like onActivityResult to be invoked on returning. But that is not the case. Is my understanding correct? Given below is the method that I would have to see called.



    // Never invoked.
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
    return;
    }
    if (requestCode == CRIME_ADD_CODE) {
    lastInsertedRowPosition =
    data.getIntExtra(CrimeListFragment.ROW_INDEX, -1);
    } else if (requestCode == CRIME_VIEW_CODE) {

    }
    }











share|improve this question























  • you call CRIME_VIEW_CODE and in your code you handle CRIME_ADD_CODE!!?

    – M.G
    Nov 25 '18 at 12:40











  • That is a request code for different click event. I am also handling CRIME_VIEw_CODE in my if block, but on activity result does not get invoked. This is where I am calling CRIME_VIEW_CODE in the click handler of the view holder. github.com/manoflogan/android-projects/blob/master/…

    – manoflogan
    Nov 25 '18 at 20:24


















0















I am an Android newbie and I need to figure out how to return data from one activity to another. The idea is that when a row in a recycler view is clicked, it will load the selected row in another activity. If the row is deleted, then the data row is deleted a list, and the control is returned the activity containing the recycler view. But I am getting the following error.



Process: com.manoflogan.criminalintent, PID: 27222
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid
view holder adapter positionViewHolder{9ed884a position=1 id=-1, oldPos=1,
pLpos:-1 scrap [attachedScrap] tmpDetached no parent}
android.support.v7.widget.RecyclerView{833ff9c VFED..... ......I.
0,0-1080,1584 #7f070032 app:id/crime_recycler_view},
adapter:com.manoflogan.criminalintent.CrimeListFragment$CrimeAdapter@4ad8da5,
layout:android.support.v7.widget.LinearLayoutManager@1abc57a,
context:com.manoflogan.criminalintent.CrimeListActivity@6a147d9
at
android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5715)
at
android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5898)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at
android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at
android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at
android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at
android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at
android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3875)
at
android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
at
android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1877)
at
android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:407)
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:693)
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2018-11-24 22:11:30.588 1608-1608/? E/lowmemorykiller: Error writing /proc/2


This is the workflow




  1. When the app starts, the user will see an empty view asking the user to
    add a new Crime by clicking on + button on the menu. Image # 1. This is the fragment responsible for rendering the home screen.


  2. When + symbol is clicked, then the user is directed to a [different activity which encapsulates a view
    pager that manages a fragment. The user can either click on the back button on the menu bar, or the device back button to see the added entries on the home screen . This is an activity that uses ViewPager to manage multiple Crime objects.


  3. The user can repeat step # 2 to add more *crimes*.



  4. To delete the crime, the user clicks/taps on any view holder (row) to go to the same activity as seen in step # 2, and then taps on the garbage icon. The item is then deleted, and the user is redirected back to the view managed by the parent's activity screen. This the block of code that invokes the activity that encapsulates the selected view.



    private class CrimeHolder extends RecyclerView.ViewHolder implements
    View.OnClickListener {
    // Child views instance variables.


    public CrimeHolder(View view) {
    super(view);
    // *. . . Initialising child views . . . *
    }

    @Override
    public void onClick(View view) {
    Intent intent = CrimePagerActivity.newIntent(getActivity(),
    mCrime.getId());
    lastAdapterClickedPosition = getAdapterPosition();

    // Invoking another activity. I would like the activity result to be handled by `onActivityResult`.
    getActivity().startActivityForResult(intent,
    CRIME_VIEW_CODE);
    }

    void bind(Crime crime) {
    mCrime = crime;
    // Setting the state of child views
    }
    }



When the user clicks the delete button, the following menu option is
triggered,



@Override
public boolean onOptionsItemSelected(MenuItem item) {
CrimeLab crimeLab = CrimeLab.get(getActivity());
Intent intent = new Intent();
switch(item.getItemId()) {
case R.id.delete_crime:
// Idea is that this index will be instantiated when activity result is returned.
intent.putExtra(CrimeListFragment.DELETE_ROW_INDEX,
crimeLab.getCrimes().indexOf(mCrime));
crimeLab.deleteCrime(mCrime);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}


Here are what I think are my issues.





  1. Ideally, when I have set my result, and have invoked finish to return to the previous activity, I would like onActivityResult to be invoked on returning. But that is not the case. Is my understanding correct? Given below is the method that I would have to see called.



    // Never invoked.
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
    return;
    }
    if (requestCode == CRIME_ADD_CODE) {
    lastInsertedRowPosition =
    data.getIntExtra(CrimeListFragment.ROW_INDEX, -1);
    } else if (requestCode == CRIME_VIEW_CODE) {

    }
    }











share|improve this question























  • you call CRIME_VIEW_CODE and in your code you handle CRIME_ADD_CODE!!?

    – M.G
    Nov 25 '18 at 12:40











  • That is a request code for different click event. I am also handling CRIME_VIEw_CODE in my if block, but on activity result does not get invoked. This is where I am calling CRIME_VIEW_CODE in the click handler of the view holder. github.com/manoflogan/android-projects/blob/master/…

    – manoflogan
    Nov 25 '18 at 20:24
















0












0








0








I am an Android newbie and I need to figure out how to return data from one activity to another. The idea is that when a row in a recycler view is clicked, it will load the selected row in another activity. If the row is deleted, then the data row is deleted a list, and the control is returned the activity containing the recycler view. But I am getting the following error.



Process: com.manoflogan.criminalintent, PID: 27222
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid
view holder adapter positionViewHolder{9ed884a position=1 id=-1, oldPos=1,
pLpos:-1 scrap [attachedScrap] tmpDetached no parent}
android.support.v7.widget.RecyclerView{833ff9c VFED..... ......I.
0,0-1080,1584 #7f070032 app:id/crime_recycler_view},
adapter:com.manoflogan.criminalintent.CrimeListFragment$CrimeAdapter@4ad8da5,
layout:android.support.v7.widget.LinearLayoutManager@1abc57a,
context:com.manoflogan.criminalintent.CrimeListActivity@6a147d9
at
android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5715)
at
android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5898)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at
android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at
android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at
android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at
android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at
android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3875)
at
android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
at
android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1877)
at
android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:407)
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:693)
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2018-11-24 22:11:30.588 1608-1608/? E/lowmemorykiller: Error writing /proc/2


This is the workflow




  1. When the app starts, the user will see an empty view asking the user to
    add a new Crime by clicking on + button on the menu. Image # 1. This is the fragment responsible for rendering the home screen.


  2. When + symbol is clicked, then the user is directed to a [different activity which encapsulates a view
    pager that manages a fragment. The user can either click on the back button on the menu bar, or the device back button to see the added entries on the home screen . This is an activity that uses ViewPager to manage multiple Crime objects.


  3. The user can repeat step # 2 to add more *crimes*.



  4. To delete the crime, the user clicks/taps on any view holder (row) to go to the same activity as seen in step # 2, and then taps on the garbage icon. The item is then deleted, and the user is redirected back to the view managed by the parent's activity screen. This the block of code that invokes the activity that encapsulates the selected view.



    private class CrimeHolder extends RecyclerView.ViewHolder implements
    View.OnClickListener {
    // Child views instance variables.


    public CrimeHolder(View view) {
    super(view);
    // *. . . Initialising child views . . . *
    }

    @Override
    public void onClick(View view) {
    Intent intent = CrimePagerActivity.newIntent(getActivity(),
    mCrime.getId());
    lastAdapterClickedPosition = getAdapterPosition();

    // Invoking another activity. I would like the activity result to be handled by `onActivityResult`.
    getActivity().startActivityForResult(intent,
    CRIME_VIEW_CODE);
    }

    void bind(Crime crime) {
    mCrime = crime;
    // Setting the state of child views
    }
    }



When the user clicks the delete button, the following menu option is
triggered,



@Override
public boolean onOptionsItemSelected(MenuItem item) {
CrimeLab crimeLab = CrimeLab.get(getActivity());
Intent intent = new Intent();
switch(item.getItemId()) {
case R.id.delete_crime:
// Idea is that this index will be instantiated when activity result is returned.
intent.putExtra(CrimeListFragment.DELETE_ROW_INDEX,
crimeLab.getCrimes().indexOf(mCrime));
crimeLab.deleteCrime(mCrime);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}


Here are what I think are my issues.





  1. Ideally, when I have set my result, and have invoked finish to return to the previous activity, I would like onActivityResult to be invoked on returning. But that is not the case. Is my understanding correct? Given below is the method that I would have to see called.



    // Never invoked.
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
    return;
    }
    if (requestCode == CRIME_ADD_CODE) {
    lastInsertedRowPosition =
    data.getIntExtra(CrimeListFragment.ROW_INDEX, -1);
    } else if (requestCode == CRIME_VIEW_CODE) {

    }
    }











share|improve this question














I am an Android newbie and I need to figure out how to return data from one activity to another. The idea is that when a row in a recycler view is clicked, it will load the selected row in another activity. If the row is deleted, then the data row is deleted a list, and the control is returned the activity containing the recycler view. But I am getting the following error.



Process: com.manoflogan.criminalintent, PID: 27222
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid
view holder adapter positionViewHolder{9ed884a position=1 id=-1, oldPos=1,
pLpos:-1 scrap [attachedScrap] tmpDetached no parent}
android.support.v7.widget.RecyclerView{833ff9c VFED..... ......I.
0,0-1080,1584 #7f070032 app:id/crime_recycler_view},
adapter:com.manoflogan.criminalintent.CrimeListFragment$CrimeAdapter@4ad8da5,
layout:android.support.v7.widget.LinearLayoutManager@1abc57a,
context:com.manoflogan.criminalintent.CrimeListActivity@6a147d9
at
android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5715)
at
android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5898)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at
android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at
android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at
android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at
android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at
android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3875)
at
android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
at
android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1877)
at
android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:407)
at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:693)
at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2018-11-24 22:11:30.588 1608-1608/? E/lowmemorykiller: Error writing /proc/2


This is the workflow




  1. When the app starts, the user will see an empty view asking the user to
    add a new Crime by clicking on + button on the menu. Image # 1. This is the fragment responsible for rendering the home screen.


  2. When + symbol is clicked, then the user is directed to a [different activity which encapsulates a view
    pager that manages a fragment. The user can either click on the back button on the menu bar, or the device back button to see the added entries on the home screen . This is an activity that uses ViewPager to manage multiple Crime objects.


  3. The user can repeat step # 2 to add more *crimes*.



  4. To delete the crime, the user clicks/taps on any view holder (row) to go to the same activity as seen in step # 2, and then taps on the garbage icon. The item is then deleted, and the user is redirected back to the view managed by the parent's activity screen. This the block of code that invokes the activity that encapsulates the selected view.



    private class CrimeHolder extends RecyclerView.ViewHolder implements
    View.OnClickListener {
    // Child views instance variables.


    public CrimeHolder(View view) {
    super(view);
    // *. . . Initialising child views . . . *
    }

    @Override
    public void onClick(View view) {
    Intent intent = CrimePagerActivity.newIntent(getActivity(),
    mCrime.getId());
    lastAdapterClickedPosition = getAdapterPosition();

    // Invoking another activity. I would like the activity result to be handled by `onActivityResult`.
    getActivity().startActivityForResult(intent,
    CRIME_VIEW_CODE);
    }

    void bind(Crime crime) {
    mCrime = crime;
    // Setting the state of child views
    }
    }



When the user clicks the delete button, the following menu option is
triggered,



@Override
public boolean onOptionsItemSelected(MenuItem item) {
CrimeLab crimeLab = CrimeLab.get(getActivity());
Intent intent = new Intent();
switch(item.getItemId()) {
case R.id.delete_crime:
// Idea is that this index will be instantiated when activity result is returned.
intent.putExtra(CrimeListFragment.DELETE_ROW_INDEX,
crimeLab.getCrimes().indexOf(mCrime));
crimeLab.deleteCrime(mCrime);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}


Here are what I think are my issues.





  1. Ideally, when I have set my result, and have invoked finish to return to the previous activity, I would like onActivityResult to be invoked on returning. But that is not the case. Is my understanding correct? Given below is the method that I would have to see called.



    // Never invoked.
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
    return;
    }
    if (requestCode == CRIME_ADD_CODE) {
    lastInsertedRowPosition =
    data.getIntExtra(CrimeListFragment.ROW_INDEX, -1);
    } else if (requestCode == CRIME_VIEW_CODE) {

    }
    }








android android-fragments android-intent android-fragmentactivity






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 9:14









manofloganmanoflogan

65




65













  • you call CRIME_VIEW_CODE and in your code you handle CRIME_ADD_CODE!!?

    – M.G
    Nov 25 '18 at 12:40











  • That is a request code for different click event. I am also handling CRIME_VIEw_CODE in my if block, but on activity result does not get invoked. This is where I am calling CRIME_VIEW_CODE in the click handler of the view holder. github.com/manoflogan/android-projects/blob/master/…

    – manoflogan
    Nov 25 '18 at 20:24





















  • you call CRIME_VIEW_CODE and in your code you handle CRIME_ADD_CODE!!?

    – M.G
    Nov 25 '18 at 12:40











  • That is a request code for different click event. I am also handling CRIME_VIEw_CODE in my if block, but on activity result does not get invoked. This is where I am calling CRIME_VIEW_CODE in the click handler of the view holder. github.com/manoflogan/android-projects/blob/master/…

    – manoflogan
    Nov 25 '18 at 20:24



















you call CRIME_VIEW_CODE and in your code you handle CRIME_ADD_CODE!!?

– M.G
Nov 25 '18 at 12:40





you call CRIME_VIEW_CODE and in your code you handle CRIME_ADD_CODE!!?

– M.G
Nov 25 '18 at 12:40













That is a request code for different click event. I am also handling CRIME_VIEw_CODE in my if block, but on activity result does not get invoked. This is where I am calling CRIME_VIEW_CODE in the click handler of the view holder. github.com/manoflogan/android-projects/blob/master/…

– manoflogan
Nov 25 '18 at 20:24







That is a request code for different click event. I am also handling CRIME_VIEw_CODE in my if block, but on activity result does not get invoked. This is where I am calling CRIME_VIEW_CODE in the click handler of the view holder. github.com/manoflogan/android-projects/blob/master/…

– manoflogan
Nov 25 '18 at 20:24














1 Answer
1






active

oldest

votes


















0














there are two options first call the startActivityForResult,
replace this:



getActivity().startActivityForResult(intent, CRIME_VIEW_CODE);


with



startActivityForResult(intent, CRIME_VIEW_CODE);


the second option you call it with getactivity() but you should override onActivityResult from the activity itself to call onActivityResult of the fragment like this :



In Activity:



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Fragment fragment = getSupportFragmentManager().findFragmentById("yourFragment");
fragment.onActivityResult(requestCode, resultCode, data);
}


and this will invoke your onActivityResult of your fragment.



I hope this could help you.






share|improve this answer
























  • Are these two steps or two different option? If you are referring to options, then are these two options exclusive to each other?

    – manoflogan
    Nov 26 '18 at 22:16











  • two different option

    – M.G
    Nov 27 '18 at 8:44











  • the issue is you call onActivityResult from the fragment and if you did that you should call it from the hosted activity... or simply call this method from activity directly.

    – M.G
    Nov 27 '18 at 8:46











  • If I choose option 1, how do I set the result in a fragment?

    – manoflogan
    Nov 28 '18 at 6:58











  • The second option worked for me. Thank you.

    – manoflogan
    Nov 28 '18 at 8:06











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%2f53466110%2fonactivityresult-is-not-called-on-when-the-activity-is-finished%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














there are two options first call the startActivityForResult,
replace this:



getActivity().startActivityForResult(intent, CRIME_VIEW_CODE);


with



startActivityForResult(intent, CRIME_VIEW_CODE);


the second option you call it with getactivity() but you should override onActivityResult from the activity itself to call onActivityResult of the fragment like this :



In Activity:



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Fragment fragment = getSupportFragmentManager().findFragmentById("yourFragment");
fragment.onActivityResult(requestCode, resultCode, data);
}


and this will invoke your onActivityResult of your fragment.



I hope this could help you.






share|improve this answer
























  • Are these two steps or two different option? If you are referring to options, then are these two options exclusive to each other?

    – manoflogan
    Nov 26 '18 at 22:16











  • two different option

    – M.G
    Nov 27 '18 at 8:44











  • the issue is you call onActivityResult from the fragment and if you did that you should call it from the hosted activity... or simply call this method from activity directly.

    – M.G
    Nov 27 '18 at 8:46











  • If I choose option 1, how do I set the result in a fragment?

    – manoflogan
    Nov 28 '18 at 6:58











  • The second option worked for me. Thank you.

    – manoflogan
    Nov 28 '18 at 8:06
















0














there are two options first call the startActivityForResult,
replace this:



getActivity().startActivityForResult(intent, CRIME_VIEW_CODE);


with



startActivityForResult(intent, CRIME_VIEW_CODE);


the second option you call it with getactivity() but you should override onActivityResult from the activity itself to call onActivityResult of the fragment like this :



In Activity:



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Fragment fragment = getSupportFragmentManager().findFragmentById("yourFragment");
fragment.onActivityResult(requestCode, resultCode, data);
}


and this will invoke your onActivityResult of your fragment.



I hope this could help you.






share|improve this answer
























  • Are these two steps or two different option? If you are referring to options, then are these two options exclusive to each other?

    – manoflogan
    Nov 26 '18 at 22:16











  • two different option

    – M.G
    Nov 27 '18 at 8:44











  • the issue is you call onActivityResult from the fragment and if you did that you should call it from the hosted activity... or simply call this method from activity directly.

    – M.G
    Nov 27 '18 at 8:46











  • If I choose option 1, how do I set the result in a fragment?

    – manoflogan
    Nov 28 '18 at 6:58











  • The second option worked for me. Thank you.

    – manoflogan
    Nov 28 '18 at 8:06














0












0








0







there are two options first call the startActivityForResult,
replace this:



getActivity().startActivityForResult(intent, CRIME_VIEW_CODE);


with



startActivityForResult(intent, CRIME_VIEW_CODE);


the second option you call it with getactivity() but you should override onActivityResult from the activity itself to call onActivityResult of the fragment like this :



In Activity:



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Fragment fragment = getSupportFragmentManager().findFragmentById("yourFragment");
fragment.onActivityResult(requestCode, resultCode, data);
}


and this will invoke your onActivityResult of your fragment.



I hope this could help you.






share|improve this answer













there are two options first call the startActivityForResult,
replace this:



getActivity().startActivityForResult(intent, CRIME_VIEW_CODE);


with



startActivityForResult(intent, CRIME_VIEW_CODE);


the second option you call it with getactivity() but you should override onActivityResult from the activity itself to call onActivityResult of the fragment like this :



In Activity:



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Fragment fragment = getSupportFragmentManager().findFragmentById("yourFragment");
fragment.onActivityResult(requestCode, resultCode, data);
}


and this will invoke your onActivityResult of your fragment.



I hope this could help you.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 8:41









M.GM.G

7591525




7591525













  • Are these two steps or two different option? If you are referring to options, then are these two options exclusive to each other?

    – manoflogan
    Nov 26 '18 at 22:16











  • two different option

    – M.G
    Nov 27 '18 at 8:44











  • the issue is you call onActivityResult from the fragment and if you did that you should call it from the hosted activity... or simply call this method from activity directly.

    – M.G
    Nov 27 '18 at 8:46











  • If I choose option 1, how do I set the result in a fragment?

    – manoflogan
    Nov 28 '18 at 6:58











  • The second option worked for me. Thank you.

    – manoflogan
    Nov 28 '18 at 8:06



















  • Are these two steps or two different option? If you are referring to options, then are these two options exclusive to each other?

    – manoflogan
    Nov 26 '18 at 22:16











  • two different option

    – M.G
    Nov 27 '18 at 8:44











  • the issue is you call onActivityResult from the fragment and if you did that you should call it from the hosted activity... or simply call this method from activity directly.

    – M.G
    Nov 27 '18 at 8:46











  • If I choose option 1, how do I set the result in a fragment?

    – manoflogan
    Nov 28 '18 at 6:58











  • The second option worked for me. Thank you.

    – manoflogan
    Nov 28 '18 at 8:06

















Are these two steps or two different option? If you are referring to options, then are these two options exclusive to each other?

– manoflogan
Nov 26 '18 at 22:16





Are these two steps or two different option? If you are referring to options, then are these two options exclusive to each other?

– manoflogan
Nov 26 '18 at 22:16













two different option

– M.G
Nov 27 '18 at 8:44





two different option

– M.G
Nov 27 '18 at 8:44













the issue is you call onActivityResult from the fragment and if you did that you should call it from the hosted activity... or simply call this method from activity directly.

– M.G
Nov 27 '18 at 8:46





the issue is you call onActivityResult from the fragment and if you did that you should call it from the hosted activity... or simply call this method from activity directly.

– M.G
Nov 27 '18 at 8:46













If I choose option 1, how do I set the result in a fragment?

– manoflogan
Nov 28 '18 at 6:58





If I choose option 1, how do I set the result in a fragment?

– manoflogan
Nov 28 '18 at 6:58













The second option worked for me. Thank you.

– manoflogan
Nov 28 '18 at 8:06





The second option worked for me. Thank you.

– manoflogan
Nov 28 '18 at 8:06




















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466110%2fonactivityresult-is-not-called-on-when-the-activity-is-finished%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

Feedback on college project

Futebolista

Albești (Vaslui)