Roboguice (1.1 and 1.2 Snapshot) injecting the wrong context in onActivityResult?

Yes, this will fail on RoboGuice 1.1. Activity. OnActivityResult() is a somewhat unusual method in that it executes before the activity's onResume() is called, thus RoboGuice doesn't know to switch the context back to the caller activity.

Up vote 0 down vote favorite share g+ share fb share tw.

OnActivityResult() is a standard Android function that is called after a child Activity closes. However, it doesn't seem to close all the way. After my child activity finishes, onActivityResult() is called in the parent.

At this point, my action is to inject a context (through a provider, non-assisted) in a new class the parent is creating, using the parcelable information that the child has just given back to me for an @Assisted parameter in that new class. However, despite finish() being called on the child, the context that is injected is not the parent--it is the child! This kills the program.

How do I get around this? Here's some code that gives you an idea of what I'm doing. In the parent: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.

OnActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_NEW_EXERCISE) { if (resultCode == RESULT_OK) { EntityExercise exercise = (EntityExercise)data.getExtras(). Get("exercise"); addNewRoutineExerciseDetail(exercise); //Toast. MakeText(this, exercise.getName(), Toast.

LENGTH_LONG).show(); } } } public RoutineExerciseDetail addNewRoutineExerciseDetail(EntityExercise exercise) { RoutineExerciseDetail detail = detailFactory. Create(exercise); detail. SetOnClickRelativeLayoutListener(mEditParamsOnClickListener); return detail; } In the child: View.

OnClickListener mListenerReturnExercise = new View.OnClickListener() { @Override public void onClick(View v) { Intent resultIntent = new Intent(); resultIntent. PutExtra("exercise", (EntityExercise)v.getTag()); //Assuming it's the tag setResult(Activity. RESULT_OK, resultIntent); finish(); } }; RoutineExerciseDetail's constructor's parameters: @Inject public RoutineExerciseDetail(ActivityBaseRoboOrm context, List list, @AddEditExercise TableLayout layout, @Assisted EntityExercise exercise) java android eclipse guice roboguice link|improve this question asked Sep 12 '11 at 8:26Guicer154.

Yes, this will fail on RoboGuice 1.1. Activity. OnActivityResult() is a somewhat unusual method in that it executes before the activity's onResume() is called, thus RoboGuice doesn't know to switch the context back to the caller activity. One of the main changes in RoboGuice 1.2 is to fix this behavior.

If you switch to 1.2 and replace any providers with ContextScopedProviders per these instructions, you should be good to go. If you need to stay with RoboGuice 1.1, you should be able to scope your context manually the following way: protected void onActivityResult(int requestCode, int resultCode, Intent data) { scope. Enter(this); try { ... } finally { scope.

Exit(this); } }.

In ActivityForResult method in Android your requestcode should be same in both the Activity. Then and only then your code will work. I hope it will help you.

That's not the issue at all. It's a context injection issue, not an if-statement triggering issue. – Guicer Sep 12 '11 at 9:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions