Have Activity A ,here am retrieving data from server .On click of button am finishing current activity and start B activity ,on click of button again i want to go A activity by finishing B activity but i dont want to reload A activity
You should have a look at the lifecyle of an activity and the activity stack. developer.android.com/guide/components/tasks-and-back-stack.html. To know more about the this developer.android.com/training/basics/activity-lifecycle/index.html. Go through the links and you should able to solve your problem.
Related
When user click on a notification, I set up a backstack of Activities A -> B, where B is on top and shown to user. I would like the lifecycles of Activity A to run, so that when user presses back button and comes to Activity A, it is already ready. What could I do to achieve this?
This cannot be possible as android will not allow us to do that, the only way I can see you can achieve this by doing your Activity A operation inside your Activity B And provide those details to Activity A when the user pressed back button.
Note: If you are showing any kind of list on Activity A or doing similar kind of work, you can have one Singleton Class where you can get your data in Activity B which required by Activity A, and provide same data to Activity A when the user pressed back button.
You should open the activity as normal but then put this line of code in the OnCreate() method to bring to the back.
moveTaskToBack(true);
My main activity have 2 buttons,say A and B
I always press A, and go to 2nd activity
Please tell how i can do this automatically, like when i open my app, main activity is on, button A pressed programatically, and what user see is activity2 ,when opening the app
PLEASE DONT TELL ME TO REMOVE BUTTON B,or USE 2nd activity only
Beacause some background threads are needed to be runned on main activity,
Write below code at the end of oncreate() of mainactivity... this will surely help you
A.performClick();
buttonA.performClick();
Add this code to your main Activity
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
this is a problem that is really a big one .
I go to activity a ,I can go to several activities like activity b ,c and d .
if I go to activity b and I press back button , I go to activity a , that right , but when I press back button again , it goes to activity b instead of leaving activity a, I press back button again and I go to activity a and If if i press it again , then I get out of activity a .
I mean , it repeat the whole way I go and then leave it .
it shouldn't be like this ,I need to leave activity a if I press back button not repeating activities .
I can't use intent for this because of another problem that I get ,I tried finish() onBackPressed , didn't work.
How can I do so ?
thanks you
In my android apps i have four activity A->B->C->D and in every activity i call web service then update the list-view and other element from the server so suppose i did delete some data from the database for Activity A and if user access the Activity B and he press the back button then Activity A should be refreshed. I did override onResume method and check the data is updated or not but didn't worked. I also tried another way but not achieve my goal.
my Activity structure is like a following
Class A Is Fragment which is having two tab and each tab contain listview
Class B Is Activity
Class C Is Activity
Class D Is Activity
I don't understand how to call web service again when press the back button and how to update fragment and activity when user press the back button. Please anybody suggest me some answer.
Thanks in advance
you can override the OnBackPressed-method. check the top-answer on that link!!
Android: Proper Way to use onBackPressed() with Toast
Start activity B from activity A with "startActivityForResult" instead of "startActivity".
In activity B you defaultly return RESULT_CANCELED -> so setResult(RESULT_CANCELED). Only when activity B is finished on purpose you return RESULT_OK.
In activity A you then just need to implement onActivityResult(). Depending on the result returned from activity B you can then do specific stuff in activity A, in your case refresh something.
Here is an example: http://www.vogella.com/articles/AndroidIntent/#usingintents_sub