Question

I use FragmentActivities in my Application and need to implement TabHost with nested Activities which can switch between one another. I use ActivityGroup for this purpose:

    public class CustomActivityGroup extends ActivityGroup {

View rootView;

public static CustomActivityGroup group;

private ArrayList<View> history;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.history = new ArrayList<View>(); 
    group = this;

      View view = getLocalActivityManager().startActivity("RegisterActivity", new Intent(this,RegisterActivity.class))
      .getDecorView();
      replaceView(view);
}

public void replaceView(View v) {

    history.add(v);

    setContentView(v);
}

public void back() {
    try {
        if (history.size() > 0) {
        history.remove(history.size() - 1);
        if (history.size() > 0) {
            setContentView(history.get(history.size() - 1));
        } else {
            finish();
        }
    } else {
        finish();
    }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

public int getHistorySize() {
    return history.size();
}

@Override
public void onBackPressed() {
    try {
        CustomActivityGroup.group.back();
    } catch (Exception ex) {

    }
    return;
}
}

I switch another FragmentActivity like this :

Intent i = new Intent(this, RegisterActivityCompl.class);

        View view = CustomActivityGroup.group.getLocalActivityManager()  
        .startActivity("RegisterActivityCompl", i  
        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))  
        .getDecorView();  

        // Again, replace the view  
        CustomActivityGroup.group.replaceView(view);

another Activity switched successfully but then it switches to initial state immediately. What can be reason of it?

Was it helpful?

Solution

I solved my issue using this tutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top