start activity from Back-Stack without call method on create in Activity - android

Activity A Call Activity B And B Call C i want to return to A ,Activity A is in BackStack how to return it without calling method onCreate in Activity

By using this code onCreate method will not call
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);

How about call the finish() of Activity B when you call the Activity C.

Related

How to get Activity from which second Activity was started?

I have activity A, MyRecyclerAdapter, and activity B.
In activity A I build MyRecyclerAdapter and start new activity B from recycler item click.
Now I need to access activity A in onDestroy method from activity B.
How can I do it?
Update:
I tried:
ActivityA parent = (ActivityA) getParent();
parent.setRead(id);
But it gives me null. I think it's because A is not a direct child of B;
For this purpose you should use startActivityForResult(intent). Then you override onActivityResult() in activity A to handle the data you receive after activity B was destroyed. In onDestroy() you'd just have to set the result with setResult(resultCode, data).
Like this you don't need to know about activity A in activity B.
I think you should create an interface class declare a method and implement it in Activity A. Then call that method from Activity B.
Alternatively you can create a Runnable in Activity A which does what you want in the run() method. Then pass the instance of that Runnable with the intent data to Activity B. Then call run on that instance object from Activity B. That should execute the code in the run() method in Activity A.

Resume Parent Activity

I have 2 Activity A and B, A calls B so, I want to Resume parent Activity (A) when B calls finish() on its Activity. Any advice will be useful.
UPDATE:
Maybe I should mention that I use fragments, each Activity has its own fragment, I call finish() from fragment hosted inside B activity and I expect to receive Resume on fragment belongs to A.
When you call Activity B, Activity A will go to background. Unless you finish Activity A while starting Activity B, it will automatically resume when Activity B finishes.
If you are calling this,
startActivity(ActivityB.class, this);
finish();
Just remove the finish(). It should work as expected.

onActivityResult of an Activity not called after startActivityForResult of Fragment

I have two activities ActivityOne and ActivityTwo each one contains one Fragment
i did startActivityForResult(mIntent, Request_code) from the fragment of the first activity (ActivityOne) for calling the second activity (ActivityTwo), the problem is onActivityResult of the second activity has not being called?
As mentioned in the comment, onActivityResult will only be called in the activity (e.g. ActivityOne) that started some other activity (e.g. ActivityTwo) for a result, using startActivityForResult(...);
You can read up on this in the developer guide here
If, by any chance, you are trying to pass something from ActivityOne to ActivityTwo,
you can use putExtra(...) in ActivityOne & use getExtra(...) in ActivityTwo.
You have to call onActivityResult method of the fragment of first activity inside onActivityResult method of first Activity. In other words you have to delegate onActivityResult method form activity to fragment. onActivityResult of your second activity will be called only if you call startActivityResult from within your second activity.
onActivityResult of your second activity will be called if u call startActivityResult from within your second activity.In your case the onActivityResult of the first activity will be called
ActivityOne onActivityResult will call onCreate of ActivityTwo.
In ActivityTwo, when you call setResult(requestNo,returnIntent), this will call the onActivityResult of ActivityOne.

Call Activity1's method from Activity 2

I have an Activity2 which needs to call method update() inside Activity1. How can I do this?
I don't want to start Activity2, just call it's method (this is because activity1 is the viewpager and activity2 is a fragment, so technically, activity1 is already visible as it is holding activity2.
Call getActivity () inside fragment, cast it to your class and use method.
Activity can't hold another activity. If you mean that from first activity you will start intent with second activity which contains fragment, and you want to call update() method from activity2, you can't do that. You need call update() in onActivityResult().
If "Activity2" is a fragment that has been started from Activity1 then this is what I would do:
((Activity1)getActivity()).someMethod();
new Activity(context).methodname();
or
Activity.methodname();

How to finish "Activity A" since "Activity B"? (Finish an Activity since other)

I'm trying to finish the Activity A since Activity B when it will finish too. The Activity B was launches since Actvity A.
So I've paused the Activity A. How can I do it?
You may try using startActivityForResult() on the Activity A to invoke the Activity B.
And then, before calling finish() on the Activity B, you should call setResult() and call finish() on the Activity A in onActivityResult()
Example here

Categories

Resources