How to manage multiple actions under one TabActivity tab

Here is the problem. In my application, I have 5 tabs that contain actions. In each of them I have to show different screens. For example, the main action of a tab is a list, and when I click on one of its elements, I want to display a second screen with a different list, which will display a different screen when the user selects an item, etc.

So, I knew that tabbed actions weren’t easy to manage, but I really think I need this solution. Indeed, each screen should contain a "Back" button, which will return to the previous screen with the previous state (the same position in the list).

To start new actions inside the tabs, I used the technique described here http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity

It works mostly well, but I ran into the problem of going back to the previous steps. My solution for now is to start a previous activity, as described on this website, but without any flag.

So here are my two real problems:

  • When I try to return to the first and main action of the tab, it seems like a new instance is being created, even if I use the Intent.FLAG_ACTIVITY_CLEAR_TOP flag. So when I do a few rounds between this activity and the next, I get a StackErrorOverFlow.

  • Since actions are accessible from different types of activities, I must always remember the actions of my parents, giving them intentions. It is really hard when I have a sequence of 5 or 6 screens, I have to remember the great parent if this action ... I am very grateful if I could just call the last action started by the local agent.

Thank you for your help, and if I do not understand, please let me know!

+4
source share
3 answers

Well, the solution (given on the site above) was as follows:

this.m_backButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(v.getContext(), Activity1.class); Activity1 parentActivity = (Activity1)getParent(); parentActivity.replaceContentView("activity1", intent, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT ); } }); 

and pull my main activity from ActivityGroup. You can see the answer here: http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity#comment-4

+2
source

I had the same question, I believe that I have a pretty good answer with some code examples in this blog article I just wrote. several android-acitivities

Let me know if this is helpful or needs improvement.

+3
source

I still have a problem with this code. I do not know how to handle the android button back. I have a graphic button to return to the last action using the method shown above, but if I try to add this behavior to the device’s physical return button, this will not work. I tried with onKeyPressent with the KEY_BACK event, but it never goes into this section of code.

Also, with this subactivism technique, I don't have any moving animation when I launch a new one. I am trying to add animation manually, but I cannot use a good technique because it is laggy:

 public void replaceContentView(String id, Intent newIntent, int flag) { View view = mLocalActivityManager.startActivity(id, newIntent.addFlags(flag)).getDecorView(); Animation animation = AnimationUtils.loadAnimation(this, R.anim.slide_right); view.startAnimation(animation); this.setContentView(view); } 

thanks

+1
source

Source: https://habr.com/ru/post/1315086/


All Articles