ActivityGroup inside TabHost does not show content after first run - android

I have issue with ActivityGroup. My app has 4 tabs, 2 of which has ActivityGroup and 2 more simple activity. The problem is that after first run of app content is shown properly, and when leave app through back button and return, tabs with activity group dont shown any content, including menus. While tabs with simple activity work properly.
D'you have any ideas?
Ok, some sort of code)
Setting this tab:
private TabSpec getFrontPageTab() {
Intent intent = new Intent(context, ActivityGroupHome.class);
return tabHost
.newTabSpec("home")
.setIndicator(
getTabView(R.drawable.tabbar_home, "str_home"))
.setContent(intent);
}
ActivityGroupHome:
public class ActivityGroupHome extends ActivityGroupBase {
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
ActivityUtils activityUtils = ActivityUtils.getInstance(this);
activityUtils.addActivityGroup("Home", this);
activityUtils.startHomeActivity("Home");
}
}
Methods from ActivityUtils:
public void startHomeActivity(String activityGroupName) {
if (activityGroupName != null) {
startHomeActivityForActivityGroup(activityGroupName);
} else {
Intent intent = new Intent(context, AsyncMainActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
}
private void startHomeActivityForActivityGroup(String activityGroupName) {
ActivityGroupListItem activityGroupItem = activityGroups
.findGroupByName(activityGroupName);
if (activityGroupItem != null) {
Intent intent = new Intent(activityGroupItem.activityGroup,
AsyncMainActivity.class);
intent.putExtra(ACTIVITY_GROUP_NAME, activityGroupItem.name);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View view = activityGroupItem.activityGroup
.getLocalActivityManager().startActivity("Home", intent)
.getDecorView();
activityGroupItem.activityGroup.setContentView(view);
activityGroupItem.stack.add("Home");
}
}

Related

Android studio: ListView to Tabbed Activity, save ratingbar rating on the tab pages

I'm making my first android app using android studio. In this APP I have a listview with 12 classes(12 items). After clicking on one class, it goes into a tabbed activity with 10 items of this class. On each tab page I have a rating bar to let people rate the item.
I set an activity for the listview, and 12 independent activities for those 12 tabbed activities. The code from listview to each tabbed activity is like this:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if(i==0){
Intent intent = new Intent(ListViewActivity.this, TabbedActivity1.class);
intent.putExtra("styleName", STYLE_NAMES[i]);
intent.putExtra("styleExample",STYLE_EXAMPLES[i]);
startActivity(intent);
}
else if(i==1){
Intent intent = new Intent(ListViewActivity.this, TabbedActivity2.class);
intent.putExtra("styleName", STYLE_NAMES[i]);
intent.putExtra("styleExample",STYLE_EXAMPLES[i]);
startActivity(intent);
}
...... // skip the other 10 tabbed activities.
}
Now the problem is: after I finish rating on the tabbed activities, I return to the ListView activity and click into each tabbed activity again, the ratings are gone.
I guess the reason is that in my code, each time I click on the item it opens a new tabbed activity, although same layout, the contents are not saved.
So I was wondering whether I should do something on the ListView activity to save the ratings. I have searched for relevant questions, but I found in their scenarios, each list item is just a simple ratingbar. But here, my list item is a tabbed activity with 10 ratingbars.
Therefore, I have no idea how to do it. I have no experience in android studio, so I don't know where to start to solve the problem. Any idea is appreciated! Thanks a lot in advance!!
First of all if all your tab activities are similar you can just create one activity instead of that many in your case 12 and pass the specific content and states via intent.
The basic approach to your question is would be store rating states in your main activity and when you open your tab activity each time you click the list items send the rate of the relevant activity with intent. Then in your tab activity update the rate with it.
To achieve this we are going to use startActivityForResult instead of startActivity because we need tab activity to return last state of rating bars.
You can see the basic example shown below here:
public class ListViewActivity extends AppCompatActivity {
private static final int REQUEST_RATE = 1;
private SparseIntArray rates = new SparseIntArray();
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(ListViewActivity.this, TabActivity.class);
intent.putExtra("styleName", STYLE_NAMES[i]);
intent.putExtra("styleExample", STYLE_EXAMPLES[i]);
intent.putExtra("position", i);
intent.putExtra("rating", rates.get(i, 0));
startActivityForResult(intent, REQUEST_RATE);
}
}
}
#Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_RATE:
if(resultCode == RESULT_OK) {
//retrieve and save rates
Bundle extras = data.getExtras();
int position = extras.getInt("position");
int rating = extras.getInt("rating");
rates.put(position, rating);
}
break;
}
}
}
public class TabActivity extends AppCompatActivity {
private RatingBar ratingBar;
private int position;
#Override protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab);
Bundle extras = getIntent().getExtras();
position = extras.getInt("position");
int rating = extras.getInt("rating");
ratingBar.setRating(rating);
}
#Override protected void onDestroy() {
//send current rating to list activity before we leave
setResult();
super.onDestroy();
}
private void setResult() {
Intent intent = new Intent();
intent.putExtra("position", position);
intent.putExtra("rating", ratingBar.getRating());
setResult(RESULT_OK, intent);
}
}

Tab Disappear when start new activity

I am developing android application which having multiple tabs.
Now in launcher activity tabs display perfectly and can navigate through the tabs.
but if i call activity(which i wanted to show as Tab) on Button Clicked then tabs seems disappear.
please refer the given code and let me know if i am doing something wrong.
This is Main TabActivity
public class MyTabActivity extends TabActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab);
TabHost tabHost=getTabHost();
TabSpec deshTab=tabHost.newTabSpec("Deshboard");
deshTab.setIndicator("Deshboard");
Intent DeshboardIntent=new Intent(this,DeshboardActivity.class);
deshTab.setContent(DeshboardIntent);
tabHost.addTab(deshTab);
TabSpec clientTab=tabHost.newTabSpec("client");
clientTab.setIndicator("client");
Intent intent=new Intent(this,ClientActivity.class);
clientTab.setContent(intent);
tabHost.addTab(clientTab);
}
}
Now i wanted to start client activity like
void onButtonClick(View view)
{
int id = view.getId();
switch(id)
{
case R.id.client_btn:
Intent clientIntent = new Intent(DeshboardActivity.this,ClientActivity.class);
startActivity(clientIntent);
break;
}
}
but when i click this button it starts new activity but NOT in tab.
what should i do to display this activity in tab on button click also.?
Below code is ClientActivity which i wanted to display as TAB.
public class ClientActivity extends Activity
{
private DatabaseHandler dbHandler;
private ListView clientListView ;
private BaseAdapter listAdapter;
TabHost tabHost;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.clientactivity);
dbHandler = new DatabaseHandler(this);
final List<Client> clientList = dbHandler.getAllclient();
clientListView = (ListView)findViewById(R.id.client_list);
listAdapter = new ClientListAdapter(this, clientList);
clientListView.setAdapter(listAdapter);
clientListView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
Client client = clientList.get(position);
Toast.makeText(getApplicationContext(), client.getFirstName(), Toast.LENGTH_LONG).show();
Intent clientInfoIntent = new Intent(getApplicationContext(), ClientInfoActivity.class);
clientInfoIntent.putExtra("client",client);
startActivity(clientInfoIntent);
//finish();
}
});
}
}
That's because your ClientActivity is launched on top of your TabActivity. That way your tabbar is not shown anymore.
I suggest you use fragments for your ClientActivity.
A tutorial how to use fragments:
http://developer.android.com/guide/components/fragments.html

TabActivity,Activities containing fragments

I have 5 tabs.Each tab contain multiple activities and each activity contain multiple fragments.
For eg:Navigation needed is In tab1 - Activity1 - Fragment1_Activity1 - Fragment2_Activity1 - Activity2 - Fragmnet1_Activity2
I used ActivityGroup to show Activity2 inside the Tabs.
ActivityGroupClass:
public class CouponsActivityGroup extends ActivityGroup {
private Stack<String> stack;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (stack == null) stack = new Stack<String>();
//start default activity
push("FirstStackActivity", new Intent(this, CouponsContianer.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) finish();
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());
}
}
}
From Fragment2_Activity1 am calling Activity2 using the following code:
Intent intent = new Intent();
intent.setClass(getParent(), RelatedItemListActivity .class);
CouponsActivityGroup activityStack = (CouponsActivityGroup) getParent();
activityStack.push("SecondStackActivity", intent);
Issue am facing now is
I want to set a transition animation for Activity2
On pressing back from Activity2 - last Fragment state in Activity1(Fragment2_Activity1) need to be maintained.
How to achieve this?
Fragments are some kind of replacement of old ActivityGroups and shouldn't be used together. Try to implement your application using only one activity and as many fragments as you need.
Answering your questions:
FragmentManager helps you to set an animation. See FragmentTransaction.setCustomAnimations .
Use addToBackStack method to support back button proper way.

Change tab host intent

I am working on an application that pulls information from the internet. The information is sorted into categories, sub-categories and, sub-sub-categories.
My main view is a TabHost view (the parent categories) with 3 tabs, and the initial list view (the sub-categories). When the user clicks an item in the list view it calls a new list view that displays the child-categories of the chosen sub-category.
I got everything to work except that when a sub category is chosen the tabHost view disappears and the sub-sub-categories are displayed in full screen.
How can I change the intent of the tab to display the child-categories of the sub-category?
EDIT: here is my code, sorry I didn't post it earlier!
My Main view which contains the tabhost:
public class tabwidget extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, category1Activity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("category1").setIndicator("Category1",
res.getDrawable(R.drawable.ic_tab_category1))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, category2Activity.class);
spec = tabHost.newTabSpec("category2").setIndicator("Category2",
res.getDrawable(R.drawable.ic_tab_category2))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, category3Activity.class);
spec = tabHost.newTabSpec("category3").setIndicator("Category3",
res.getDrawable(R.drawable.ic_tab_category3))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
When the application is started the alcohol tab is selected by default. This is the category1Acitivity listview with the onlclick action that calls the child-categories:
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Toast.makeText(getApplicationContext(), "You clicked item at position"+position,
//Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Loading "+((TextView) view.findViewById(R.id.categoryname)).getText(),
Toast.LENGTH_SHORT).show();
Intent i = new Intent(category1Activity.this, subCategoryActivity.class);
i.putExtra("id", ((TextView) view.findViewById(R.id.message)).getText());
i.putExtra("catname", ((TextView) view.findViewById(R.id.categoryname)).getText());
i.putExtra("parentcatid", "0");
startActivityForResult(i, ACTIVITY_CREATE);
}
});
The listviews are generated by the category Id which is sent to the server pulls results from the database.
You will have to use ActivityGroups to do that.
http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html
http://united-coders.com/nico-heid/use-android-activitygroup-within-tabhost-to-show-different-activity
However, keep in mind that ActivityGroups are deprecated in ICS.
EDIT: This is my implementation of ActivityGroup:
Activity in a tab:
Intent i = new Intent(v.getContext(), SearchList.class);
i.putExtra("search", search);
View view = SearchActivityGroup.group.getLocalActivityManager()
.startActivity("SearchList", i
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Again, replace the view
SearchActivityGroup.group.replaceView(view);
ActivityGroup:
package nl.dante.SuperDeals;
import java.util.ArrayList;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class SearchActivityGroup extends ActivityGroup {
View rootView;
// Keep this in a static variable to make it accessible for all the nested
// activities, lets them manipulate the view
public static SearchActivityGroup group;
// Need to keep track of the history if you want the back-button to work
// properly, don't use this if your activities requires a lot of memory.
private ArrayList<View> history;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* this.history = new ArrayList<View>(); group = this;
*
* // Start the root activity within the group and get its view View
* view = getLocalActivityManager().startActivity("Search", new
* Intent(this,Search.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
* .getDecorView();
*
* // Replace the view of this ActivityGroup replaceView(view);
*/
}
#Override
protected void onResume() {
super.onResume();
this.history = new ArrayList<View>();
group = this;
// Start the root activity within the group and get its view
View view = getLocalActivityManager().startActivity("Search", new Intent(this, Search.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
// Replace the view of this ActivityGroup
replaceView(view);
}
public void replaceView(View v) {
// Adds the old one to history
if (history.size() == 0) {
if (rootView != null) {
history.add(rootView);
rootView = null;
}
}
history.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
public void back() {
try {
if (history.size() > 0) {
if (history.size() == 1) {
rootView = history.get(0);
Toasts.ToastImageView(this, "Druk nogmaals BACK om af te sluiten", R.drawable.power_64_off, "red");
}
history.remove(history.size() - 1);
setContentView(history.get(history.size() - 1));
} else {
finish();
}
if (history.size() < 3) {
// Tabhost.bannerImage2.setImageResource(0);
Tabhost.banner.setBackgroundResource(R.drawable.gradient_blue);
}
if (history.size() == 2) {
Tabhost.bannerImage1.setImageResource(R.drawable.sorteer_btn);
}
} catch (Exception ex) {
}
}
public int getHistorySize() {
return history.size();
}
#Override
public void onBackPressed() {
try {
SearchActivityGroup.group.back();
} catch (Exception ex) {
}
return;
}
}

Switching between tab using activity group it want to display last activity - Tab ActivityGroup

I have written tab for my android application.
My question is switching between tab using activity group it want to display last activity. I want to show last open/visited screen when we navigate the tab.My one is go to first screen:
I need to show last opened screen when navigate through Tab
Tab 1 -> Sales. This contain 10 screen inside (actiivity)
Tab 2 -> Admin .This contain 5 screen inside (actiivity)
Tab 3 -> Setting.This contain 8 screen inside. (actiivity)
I clicked Tab 1 , it load tab 1's screen which is contain list of sales route .then I clicked one sales route , it goes to list of retailer in the first tab.Then I cliched tab 3 "Setting " finish some work & come back to sales, That time it should show last open screen in the "sales" tab.
When I clicked tab, It should show last open activity How to do?
I did like this.Please indicate where I want to change the code for my requirements.
MainActivity.It will call after login
public class MainActivity extends TabActivity {
int selectedTab;
TabHost tabHost ;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabview);
TabHost t = getTabHost();
tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
TabSpec thirdTabSpec = tabHost.newTabSpec("tid1");
/** TabSpec setIndicator() is used to set name for the tab. */
/** TabSpec setContent() is used to set content for a particular tab. */
firstTabSpec.setIndicator("Sales").setContent(new Intent(this,SalesActivityGroup.class));
secondTabSpec.setIndicator("Admin").setContent(new Intent(this,SettingActivityGroup.class));
thirdTabSpec.setIndicator("Setting").setContent(new Intent(this,SettingActivityGroup.class));
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec);
tabHost.setCurrentTab(0);
tabHost.setMinimumHeight(25);
}
public void onTabChanged(String arg0) {
selectedTab = tabHost.getCurrentTab();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(false);
return true;
}
return super.onKeyDown(keyCode, event);
}
}
First Tab1(Sales)'s SalesGroupActivity
public class SalesActivityGroup extends ActivityGroup {
public static SalesActivityGroup 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("Sales",
new Intent(this, SalesRouteActivity.class).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() > 0) {
history.remove(history.size() - 1);
if (history.size() > 0) {
setContentView(history.get(history.size() - 1));
} else {
finish();
}
} else {
finish();
}
}
#Override
public void onBackPressed() {
SalesActivityGroup.group.back();
return;
}
Edited
This is FirstTab's firstActivity - SalesRouteActivity
public class SalesRouteActivity extends ListActivity{
TableLayout tl;
static int positions = 0;
static String keyword ="";
int uploadSize = 0;
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
String strBusinessUnit = "";
String strExecutive = "";
String strTerritoryCode = "";
SimpleAdapter sd;
View row = null;
View selectRow = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sales_routes);
SharedPreferences myPrefs = this.getSharedPreferences("myLogedPrefs",MODE_WORLD_READABLE);
strBusinessUnit = myPrefs.getString("BusinessUnit", "");
strExecutive = myPrefs.getString("Executive", "");
strTerritoryCode = myPrefs.getString("TerritoryCode", "");
ArrayList<SalesRoutes> routeList = getSalesRoute();
ArrayList<HashMap<String, String>> routhPath = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < routeList.size(); i++) {
if(Integer.parseInt(routeList.get(i).getOutlets()) >0){
HashMap<String, String> map = new HashMap<String, String>();
map.put("routeCode",((SalesRoutes) routeList.get(i)).getRouteCode());
map.put("routeName",((SalesRoutes) routeList.get(i)).getDescription());
map.put("outlets", ((SalesRoutes) routeList.get(i)).getOutlets());
routhPath.add(map);
}
}
ListView list = getListView();
sd = new SimpleAdapter(this, routhPath, R.layout.route_path,new String[] {"routeCode","routeName","outlets" },new int[] { R.id.routeCode,R.id.routeName,R.id.outlets});
row = getLayoutInflater().inflate(R.layout.route_path_row, null, false);
getListView().addHeaderView(row);
list.setAdapter(sd);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setSelected(true);
list.setTextFilterEnabled(true);
list.setItemsCanFocus(true);
list.setItemChecked(positions, true);
list.setSelectionAfterHeaderView();
if (routeList.size() > 0) {
keyword = routeList.get(0).getRouteCode();
}
uploadSize = new UploadActivity().getUploadTable();
if (uploadSize > 0) {
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.icon, "New Alert, Click Me!",System.currentTimeMillis());
Context context = getApplicationContext();
CharSequence contentTitle = "Upload Available...";
CharSequence contentText = "Browse Android Official Site by clicking me";
Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));
PendingIntent intent = PendingIntent.getActivity(SalesRouteActivity.this, 0, notifyIntent,android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle,contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
}
}
#SuppressWarnings("unchecked")
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
HashMap<String, String> hashMap = (HashMap<String, String>) l.getItemAtPosition(position);
keyword = hashMap.get("routeCode");
positions = position;
if(position == 0 ){
}else if(position != 1){
Intent showContent = new Intent(v.getContext(),SalesRouteDevitionActivity.class);
Bundle bundle = new Bundle();
bundle.putString("RouteCode", keyword);
showContent.putExtras(bundle);
getParent().startActivityForResult(showContent, 5);
}else{
Intent intent = new Intent(SalesRouteActivity.this, ListRetailerActivity.class);
Bundle bundle = new Bundle();
bundle.putString("RouteName", keyword);
intent.putExtras(bundle);
View view = SalesActivityGroup.group.getLocalActivityManager().startActivity("", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
SalesActivityGroup.group.replaceView(view);
}
}
#Override
public void onBackPressed() {
SalesActivityGroup.group.back();
}
#SuppressWarnings({ "rawtypes", "unchecked" })
public ArrayList<SalesRoutes> getSalesRoute(){
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);
try {
dbAdapter.createDataBase();
} catch (IOException e) {
Log.i("*** select ",e.getMessage());
}
dbAdapter.openDataBase();
String sql = "SELECT RouteCode, Description, OutletsAttached " +
"FROM WMRoute " +
"WHERE ActiveStatus = '1' AND RouteDefaultExecutive = ? AND BusinessUnit = ? AND TerritoryCode = ? " +
"ORDER BY RouteCode ";
String[]d = new String[]{strExecutive,strBusinessUnit,strTerritoryCode};
ArrayList stringList = dbAdapter.selectRecordsFromDBList(sql, d);
dbAdapter.close();
ArrayList<SalesRoutes> salesRoutesList = new ArrayList<SalesRoutes>();
for (int i = 0; i < stringList.size(); i++) {
ArrayList<Object> arrayList = (ArrayList<Object>) stringList.get(i);
ArrayList<Object> list = arrayList;
SalesRoutes salesRoutes = new SalesRoutes();
try {
salesRoutes.setRouteCode((String) list.get(0));
salesRoutes.setDescription((String) list.get(1));
salesRoutes.setOutlets((String)list.get(2));
} catch (Exception e) {
Log.i("***" + SalesRouteActivity.class.toString(), e.getMessage());
}
salesRoutesList.add(salesRoutes);
}
return salesRoutesList;
}
}
probably my ActivityGroups are being created again and again when you switch between tabs
So groups want to create only once and resumed when i switch between tabs
Every screen details/contents getting from database..
I am facing this issue more than 2 days....Please help me.
Please help me on this....
Thanks in advance.....
I think you have to override onBackPressed() inside activities which you are opening in activity-group
Write a code below in each activity which you are opening in activity-group
#Override
public void onBackPressed() {
SalesActivityGroup.group.back();
}
And also replace the onBackPressed() with following code in TABHOST
#Override
public void onBackPressed() {
super.onBackPressed();
}
Best of luck
The activity groups you created will hold your current activity view will not change unless you change it, Therefore while you are navigating between tabs the activity groups you have assigned to those tabs will not change their views will remain as it is.
You can try this ....
For each of your activity you must override onBackPressed() ...
#Override
public void onBackPressed() {
ActivityGroupRelatedToThisActivity.group.back();
}
Also remember do not call super.onBackPressed() in any of your Activity which is related to activity group
Or
Change private ArrayList<View> history to static private ArrayList<View> history
and
if(history.size() == 0) replaceView(view);
in ActivityGroup's onCreate() method
This answer will be help you. I have used the group activity for my tabs. Let me know if you still find the problem
Why Back button is not detecting in muti tab activities?
I think you are having a problem in back() of ActivityGroup, please try this.
public void back()
{
if ( history.size() > 1 )
{
history.remove(history.size() - 1);
View v = arrList.get(history.size() - 1);
setContentView(v);
}
else {
this.finish();
}
}
Thanks All;
There were issue in my MainActivity.
tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, SalesActivityGroup.class);
spec = getTabHost().newTabSpec("Sales").setIndicator("Sales",getResources().getDrawable(R.drawable.ic_tab_artists_grey)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SettingActivityGroup.class);
spec = getTabHost().newTabSpec("Admin").setIndicator("Admin",getResources().getDrawable(R.drawable.admin)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SettingActivityGroup.class);
spec = getTabHost().newTabSpec("Setting").setIndicator("Setting",getResources().getDrawable(R.drawable.ic_tab_artists_grey)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SettingActivityGroup.class);
spec = getTabHost().newTabSpec("Inquiry").setIndicator("Inquiry",getResources().getDrawable(R.drawable.ic_tab_artists_grey)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
tabHost.setMinimumHeight(18);
tabHost.setFadingEdgeLength(5);
tabHost.setFocusable(true);
tabHost.requestFocus();
tabHost.setFadingEdgeLength(5);
}
}
And I agree #Vaibhav Jani #Dharmendra #Suri, I missed that onKeyPressed() in all Activity.
I saw your update. I'm not sure how to answer your question. Perhaps you can save information about what view is currently being diplayed in onSavedInstanceState and fetch the data it in onRestoreInstancestate and use it to recreate the view. As a side note, ActivityGroup is deprecated, and has been replaced by the Fragment API.

Categories

Resources