0

I have the following ActivityGroup

public class ActivityStack extends ActivityGroup{

    public static int settingsFlag=0;
    private Stack<String> stack;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (stack == null)
            stack = new Stack<String>();
        // start default activity
        settingsFlag=1;
        push("FirstStackActivity", new Intent(this, ChannelsActivity.class));
    }

    @Override
    public void finishFromChild(Activity child) {
        pop();
    }

    @Override
    public void onBackPressed() {
        pop();
    }

    public void push(String id, Intent intent) {



        Window window = getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        if (window != null) {
            stack.push(id);    

            setContentView(window.getDecorView());
        }

    }

    public void pop() {
        if (stack.size() == 1)
        {
            if (getParent() instanceof MainActivity) {
                ((MainActivity) getParent()).changeToMainTabs();
            } 
        } else {
        LocalActivityManager manager = getLocalActivityManager();
        manager.destroyActivity(stack.pop(), true);
        if (stack.size() > 0) {
            Intent lastIntent = manager.getActivity(stack.peek()).getIntent();
            Window newWindow = manager.startActivity(stack.peek(), lastIntent);    
            setContentView(newWindow.getDecorView());
        }
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        //what is the current activity?
        menu.add(0, 0, 0, "holder");
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu)
    {
        //start a new
        menu.clear();
        //add some menu options
        getLocalActivityManager().getCurrentActivity().onPrepareOptionsMenu(menu);
        return super.onPrepareOptionsMenu(menu);
    }
}

And I have this code in another Activity:

editTxt.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            Intent countryIntent = new Intent();
                                                    countryIntent.setClass(getParent(),Test.class);
                            //startActivityForResult(countryIntent, requestCode);

                            ActivityStack activityStack = (ActivityStack) getParent();
                            **activityStack.push("SecondActivity", startActivityForResult(countryIntent, requestCode)); //!!THIS SI NOW WORKING CASE IT EXPECTS AN INTENT**
                        }
                    });

How can I make this work? Can someone please help?

just ME
  • 1,817
  • 6
  • 32
  • 53

1 Answers1

2

For receive push try the following code in your main group activity'

   @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//code for receive the data
    } 

means put the above code in ActivityStack activity

Yogesh Tatwal
  • 2,722
  • 20
  • 43
  • so I should put in activityStack.push("SQecondActivity,countryIntent)? or what should I have in push method? I know I need to have the metnof onACtivityResult in case I have that startActivityForResult. I;ve edit my code. – just ME May 27 '13 at 08:32
  • yes because it will return value to its parent not child u have to put it and no need for edited – Yogesh Tatwal May 27 '13 at 09:12
  • thank you for your replay but I don't need t use onActivityResult. I've changed my code witn Intent. My app fails on line Intent lastIntent = manager.getActivity(stack.peek()).getIntent(); – just ME May 27 '13 at 11:29
  • In the second activity that I am calling and with is actually a listActivity I call a finish method. – just ME May 27 '13 at 11:30
  • Ok but always remember in activitygroup its return value to its parent not child i think u got your solution congrats. – Yogesh Tatwal May 27 '13 at 11:47