I have activity A and Activity B.
Activity A start Activity B by intent.
After Activity B have a event (example event D), I make a listener to Activity A and I want to Activity A close Activity B because i can't modify Activity B.
What is the solution in my case ?
Thanks,
Related
Description:
I have an activity (Activity A) with a button that changes to another activity (Activity B) which has another 3 buttons. Button A goes to Fragment A, Button B goes to Fragment B and Button C goes to Fragment C. I am overriding onBackPressed method:
Question:
How can I manage onBackPressed method in order you canĀ“t go back to Activity A (which is a login activity) but can go back, for example, from fragment C to B?
Edit:
I am using the following script to go back between fragments:
getActivity().onBackPressed();
You can remove an activity from the history stack. You can achieve this by setting the android:noHistory attribute to "true" on Activity A.
<activity
android:name=".Activity_A"
android:noHistory="true" />
but if this is a particular case you can launch your activity A from other Activity D in this way
//From activity D
val intent = Intent(this, Activity_A.class)
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
startActivity(intent)
Other way to remove Activity_A from stack is calling finish() after launch your Activity B
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.
I have 2 activities Activity A and Activity B.
Activity B start on click of button in Activity A.
I want to start Activity B in background when the Activity A is created and move to Activity B when I click on button in Activity A.
Please help me. Thanks
If you want something that runs in background , then you go for service not the activity
I have a problem with navigating through activities. I am navigating from HomeActivity to Activity A. When I move from Home to Activity A, I finish the HomeActivity and starts another activity Activity B. When I start Activity B, I am not finishing Activity A. So when I finish Activity B normally it should go to Activity A. But In my case it is not working. When I call finish() in Activity B, both Activity B and Activity A is getting finished.
Can anybody suggest a way to accomplish this?
I have a widget for my application, which need to be somewhat independent from the app.
The activity workflow should be like this:
Widget -> Activity acting as receiver
Receiver -> LoginPage or Activity A (depending on login status)
LoginPage -> Activity A
Activity A onKeyDown -> Activity B
Activity B onKeyDown -> Home Screen.
I have no problem until Activity B, which sends back to Activity A when I press onKeyDown. I'm using FLAG_ACTIVITY_CLEAR_TOP flag and finishing the Activity when starting the activity B.
When I move from ActivityA to ActivityB using the CLEAR_TOP flag, I supposed that Activity stack is cleared, then in ActivityB I finish the Activity on the onKeyDown() method, assuming that the App will be closed, but it doesnt. Why?
I'm also trying to use FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK in the receiver but I dont understand the mechanism pretty much. Any idea about this?
In fact the FLAG_ACTIVITY_CLEAR_TOP, start your activity B if its not started or it came back as the second activity on the BackStack. To finish Activity A, you can call finish() after starting Activity B or add no history flag, when starting A.
#JesusS: I doubt if u can finish ur activity in that fashion during a forward transition.
Consider a scenario of moving from Activity A to Activity B. Now if u want to kill Activity A and want to move to Activity B then call the startActivity(intent);
(where ur moving from activity A to B)
without any flags on the intent followed by the finish() on activity A.
As per my understanding u can use Intent.FLAG_ACTIVITY_CLEAR_TOP only during backward transition i.e when u already have that activity on the stack.
Consider the following scenario:
A --> B --> C --> D
Now if u want to move back from activity D to Activity A by clearing the activities u can go for Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP.
The result is that the Activities D, C, B(LIFO) will be removed from the stack and the activity A resumes by calling the onResume() of Activity A.