Piraba
Piraba

Reputation: 7014

Android ActivityGroup's child activity setTitle not working

I have TabActivityGroup:

MainActivity class contain some tab, that name loading from db. Sales, Admin, Inquiry like wise I have tab name

For Sales I created SalesActivityGroup.That class is :

public class SalesActivityGroup extends ActivityGroup {
   public static SalesActivityGroup group;
   private  ArrayList<View> history;
   private LocalActivityManager mActivityManager;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       this.history = new ArrayList<View>();
       group = this;
         mActivityManager = getLocalActivityManager();
        Intent i = new Intent(getBaseContext(), SalesRouteActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt("positions", -1);
        i.putExtras(bundle);
        View view = mActivityManager.startActivity("Sales",i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP )).getDecorView();
    replaceView(view);

}

public void replaceView(View v) {
    history.add(v);
    setContentView(v);
}

public void back(){
    if ( history.size() > 1 ){
       history.remove(history.size() - 1);
       View v = history.get(history.size() - 1);
       setContentView(v);
    }
    else {
       this.finish();
    }
}

@Override
public void onBackPressed() {
    SalesActivityGroup.group.back();
}
}

SalesRouteActivity is first Activity .In there i want to set up the title name.I did using this ways.But not working

 public class SalesRouteActivity extends Activity{
       @Override
       public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // setContentView(R.layout.sales_routes);
      //getWindow().setTitle("Route");
          View viewToLoad = LayoutInflater.from(SalesActivityGroup.group).inflate(R.layout.sales_routes, null);
         this.setContentView(viewToLoad); 
         //this.setTitle("Route");
        //getWindow().setTitle("Route");
         SalesActivityGroup.group.setTitle("Route");
    }

}

Please advice me How can i set the Title name.

Thanks in advance

Upvotes: 0

Views: 1977

Answers (3)

pikini
pikini

Reputation: 185

The best way to do this is to implement the method

protected void onChildTitleChanged(Activity childActivity,CharSequence title) {
    super.onChildTitleChanged(childActivity, title);
    setTitle(title);
}

Implement this method in the parent activity. For example, In my case I have three activities.

  1. Home Activity
  2. Artists Activity
  3. Album Activity

My Home activity contains a TabHost with Artists activity and Album activity. I implemented the above method in the Home Activity. The title for Artists activity and Album activity is set in the OnResume methods of those respective activities.

Upvotes: 1

blessanm86
blessanm86

Reputation: 31779

You can access the parent tab activity like

getParent().getParent().setTitle("New Tilte");

EXPLANATION:

Based on my understanding, When you call the getParent the first time, you get the activity group that started the child activity.

When you call getParent the second time, you will get the tab activity that started the activity group.

setTitle should work for the activity window which is held by the tabactivity. The sub activities are rendered in the framelayout of the tab activity. So in the child activities access the parent tab activity to set the title.

Upvotes: 2

Rajdeep Dua
Rajdeep Dua

Reputation: 11230

It is not advisable to use ActivityGroup, it has been deprecated.
Refer to this link Please use Fragment and FragmentManager using Compatibility Library

Upvotes: 0

Related Questions