Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:47:21+00:00 2026-06-15T03:47:21+00:00

Basically, I’m working on a app which has a tab-activity including 4 tabs and

  • 0

Basically, I’m working on a app which has a tab-activity including 4 tabs and also I’m using the actvityGroup to manage the activities and backKey pressed() method.

When my app first starts it sends a request to server and shows the progress bar (using AsyncTask) as shown in below image.

enter image description here

After this, my complete UI appears as

enter image description here

it loads new actvity on click event of button “GO” (code is given below)

btnGo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                Intent bookSearchResultActivityIntent = new Intent();
                bookSearchResultActivityIntent
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                bookSearchResultActivityIntent.setClass(getParent(),
                        BookSearchResultActivity.class);
                bookSearchResultActivityIntent.putExtra("LANG", language);
                bookSearchResultActivityIntent.putExtra("SEARCH_KEYWORDS",
                        edTxt_SearchField.getText().toString());
                MyActivityGroup activityStack = (MyActivityGroup) getParent();
                activityStack.push("BooksSearchActivity",
                        bookSearchResultActivityIntent);

also here is my ActivtyGroup.java code

public class MyActivityGroup extends ActivityGroup {
    private Stack<String> stack;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (stack == null) {
                stack = new Stack<String>();
        }
        push("1stStackActivity", new Intent(this, Home.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()
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            Window newWindow = manager.startActivity(stack.peek(), lastIntent);
            setContentView(newWindow.getDecorView());
        }
    }
}

ok now my question is that when i press the backKey(); it should come to the previous actvity.

  • Yes it comes to the previous activity but it send request to the server again and shows the progress bar again and loads until the server sends response. it wastes my time.
  • I only want to load the HomeTab just once (when i play the app). not again and again
  • I am also adding the

    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

while starting the activity

  • also added following code in menifest.xml file

    android:configChanges=”keyboard|keyboardHidden|orientation”

but not working yet.

and here is the code of my Home tab(which sends the request to server in onCreate method)

public class Home extends Activity {
    /** Called when the activity is first created. */
    static final String URL = "http://www.shiaislamiclibrary.com/requesthandler.ashx";
    static final String KEY_ITEM = "Book"; // parent node
    static final String KEY_BOOKAUTHOR = "BookAuthor";
    static final String KEY_BOOKDATEPUBLISHED = "DatePublished";
    static final String KEY_BOOKTITLE = "BookTitle";
    static final String KEY_BOOKCODE = "BookCode";
    static final String KEY_BOOKIMAGE = "BookImage";

    String searchLang;
    String searchKeywords;
    LayoutInflater inflater = null;

    ArrayList<String> BookTitle = new ArrayList<String>();
    ArrayList<String> BookCoverPhotos = new ArrayList<String>();
    ArrayList<String> BookAuther = new ArrayList<String>();
    ArrayList<String> BookPublishDate = new ArrayList<String>();
    ArrayList<String> ImageByte = new ArrayList<String>();
    ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();

    Context ctx = this;
    Activity act = this;
    Context context = Home.this;
    URL bookImageURL = null;
    Bitmap bitMapImage = null;

    Button btnGo;
    Spinner spnrLanguage;
    Spinner spnrBrowseBy;
    String language;
    EditText edTxt_SearchField;

    GridView gridView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // setContentView(R.layout.home_activity);
        View viewToLoad = LayoutInflater.from(this.getParent()).inflate(
                R.layout.home_activity, null);
        this.setContentView(viewToLoad);

        gridView = (GridView) findViewById(R.id.gridview);
        spnrLanguage = (Spinner) findViewById(R.id.spnrLanguage);
        spnrBrowseBy = (Spinner) findViewById(R.id.spnrBrowseBy);
        edTxt_SearchField = (EditText) findViewById(R.id.EditTxt_Search);
        btnGo = (Button) findViewById(R.id.btn_GO);

        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        // checking for availbe internet Connection
        if (cm.getActiveNetworkInfo() != null
                && cm.getActiveNetworkInfo().isAvailable()
                && cm.getActiveNetworkInfo().isConnected()) {

            new UIThread().execute(URL, "Imam Ali");
        }

        gridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
                    long arg3) {

                Toast.makeText(context, BookTitle.get(pos), Toast.LENGTH_SHORT)
                        .show();

                Intent bookSearchResultActivityIntent = new Intent();
                bookSearchResultActivityIntent.setClass(getParent(),
                        BookOverView.class);
                bookSearchResultActivityIntent.putExtra("BITMAP",
                        bitmapArray.get(pos));
                bookSearchResultActivityIntent.putExtra("BOOK_TITLE",
                        BookTitle.get(pos));
                bookSearchResultActivityIntent.putExtra("BOOK_AUTHOR",
                        BookAuther.get(pos));
                bookSearchResultActivityIntent.putExtra("BOOK_PUBLISH_DATE",
                        BookPublishDate.get(pos));

                MyActivityGroup activityStack = (MyActivityGroup) getParent();
                activityStack.push("BookOverViewActivity",
                        bookSearchResultActivityIntent);

            }
        });

        // //////////////////// Spinners handler/////////////////////////
        ArrayAdapter<String> adapterLanguage = new ArrayAdapter<String>(
                context, android.R.layout.simple_spinner_item, getResources()
                        .getStringArray(R.array.spnr_language_array));
        ArrayAdapter<String> adapterBrowseBy = new ArrayAdapter<String>(
                context, android.R.layout.simple_spinner_item, getResources()
                        .getStringArray(R.array.spnr_browse_array));
        spnrLanguage.setAdapter(adapterLanguage);
        spnrBrowseBy.setAdapter(adapterBrowseBy);

        spnrLanguage.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
                    long arg3) {
                Toast.makeText(getParent(),
                        spnrLanguage.getItemAtPosition(pos) + "",
                        Toast.LENGTH_SHORT).show();
                language = spnrLanguage.getItemAtPosition(pos).toString();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }
        });

        spnrBrowseBy.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
                    long arg3) {
                Toast.makeText(context,
                        spnrBrowseBy.getItemAtPosition(pos) + "",
                        Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }
        });

        // ////////////////////Search Button Handler/////////////////

        btnGo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (!edTxt_SearchField.getText().toString().equals("")) {
                    Intent bookSearchResultActivityIntent = new Intent();
                    bookSearchResultActivityIntent
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    bookSearchResultActivityIntent.setClass(getParent(),
                            BookSearchResultActivity.class);
                    bookSearchResultActivityIntent.putExtra("LANG", language);
                    bookSearchResultActivityIntent.putExtra("SEARCH_KEYWORDS",
                            edTxt_SearchField.getText().toString());
                    MyActivityGroup activityStack = (MyActivityGroup) getParent();
                    activityStack.push("BooksSearchActivity",
                            bookSearchResultActivityIntent);

                } else {
                    Toast.makeText(context, "Search Field Empty",
                            Toast.LENGTH_SHORT).show();
                }

            }
        });

    }

    private class UIThread extends AsyncTask<String, Integer, String> {

        ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            progressDialog = ProgressDialog.show(getParent(),
                    "Acumlating Books from server...",
                    "This may Take a few seconds.\nPlease Wait...");
        }

        @Override
        protected String doInBackground(String... params) {

            String URL = params[0];
            String searchKeywords = params[1];

            XMLParser parser = new XMLParser();
            String XMLString = parser.getXmlFromUrl(URL, searchKeywords,
                    searchLang);
            // Log.i("XML Response", XMLString);

            Document doc = parser.getDomElement(XMLString);

            NodeList nl = doc.getElementsByTagName(KEY_ITEM);

            // looping through all item nodes <item>
            for (int i = 0; i < nl.getLength(); i++) {
                Element e = (Element) nl.item(i);

                BookTitle.add(parser.getValue(e, KEY_BOOKTITLE));
                BookCoverPhotos.add("http://shiaislamicbooks.com/books_Snaps/"
                        + parser.getValue(e, KEY_BOOKCODE) + "/1_thumb.jpg");
                BookAuther.add(parser.getValue(e, KEY_BOOKAUTHOR));
                BookPublishDate.add(parser.getValue(e, KEY_BOOKDATEPUBLISHED));
                Log.i("URLs", BookCoverPhotos.toString());
            }
            for (int i = 0; i < BookAuther.size(); i++) {

                try {
                    bookImageURL = new URL(BookCoverPhotos.get(i));
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                    Log.i("URL", "ERROR at image position" + i + "");
                }

                try {
                    bitMapImage = BitmapFactory.decodeStream(bookImageURL
                            .openConnection().getInputStream());
                    bitmapArray.add(bitMapImage);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.i("BITMAP", "ERROR" + i);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);

            progressDialog.dismiss();
            ImageAdapter adapter = new ImageAdapter(getBaseContext(), act);
            gridView.setAdapter(adapter);
        }
    }

    public class ImageAdapter extends BaseAdapter {

        public ImageAdapter(Context c) {
            context = c;
        }

        // ---returns the number of images---
        public int getCount() {
            // return imageIDs.length;
            return bitmapArray.size();
            // return 6;
        }

        public ImageAdapter(Context ctx, Activity act) {

            inflater = (LayoutInflater) act
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        // ---returns the ID of an item---
        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        // ---returns an ImageView view---
        public View getView(int position, View convertView, ViewGroup parent) {

            // ImageView bmImage;

            final ViewHolder holder;
            View vi = convertView;
            if (convertView == null) {
                vi = inflater.inflate(R.layout.grid_style, parent, false);
                holder = new ViewHolder();
                holder.txt_BooksTitle = (TextView) vi
                        .findViewById(R.id.txt_BookTitle);

                holder.img_BookCoverPhoto = (ImageView) vi
                        .findViewById(R.id.imgBookCover);
                vi.setTag(holder);
            } else {

                holder = (ViewHolder) vi.getTag();
            }
            holder.txt_BooksTitle.setText(BookTitle.get(position) + "");
            holder.img_BookCoverPhoto.setImageBitmap(bitmapArray.get(position));
            return vi;
        }
    }

    class ViewHolder {
        TextView txt_BooksTitle;
        ImageView img_BookCoverPhoto;
    }
}
  • please have a look on my activity group class and tell what should i do.
    thanks in advance
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:47:23+00:00Added an answer on June 15, 2026 at 3:47 am

    When loading your data in the Home Tab activity, put it inside some static arrays.

        ArrayList<String> BookTitle = new ArrayList<String>();
        ArrayList<String> BookCoverPhotos = new ArrayList<String>();
        ArrayList<String> BookAuther = new ArrayList<String>();
        ArrayList<String> BookPublishDate = new ArrayList<String>();
        ArrayList<String> ImageByte = new ArrayList<String>();
        ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
    

    From a quick glimpse on the code, make them static ArrayList<...> ... = null; and check inside the onCreate() method:

    if(BookTitle == null)
    {
        //needs init
        BookTitle = new ArrayList<String>();
        //perform connect to server and parse response.
    }
    

    When the application activity home tab is stopped then restarted, the data will be in memory already and it will skip the if clause keeping the old data for re-use.

    Make sure you will clear the static variables when you really want to kill the app – on a quit button click, call a static method to init them to null again, or if you want them to be valid for let’s say 12 hours, memorize the timestamp in a static variable and each time you kill/pause the main activity perform a check on it (wheather is null or has a date, if it has a date, check if 12 hours have passed, if yes, clear the static variable contents)

    This is the quick and easy way. Another way is to store them in the application database if you don’t want to deal with static variables.

    There are a lot of options, the point is you kinda have to mark them as “global persistent” data with static, or store them in a databse / file etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to check the extended permissions the user has granted my app.
Basically, what I'm trying to create is a page of div tags, each has
Basically I have converted a tab delimited txt file into a list containing a
Basically I am wondering about having this behavior in an app where the newer
Basically, I'm developing a note-taking app where the user can type as long as
Basically, I have a JTextPane to hold some text which I wish to style.
Basically, I'm implemeting a reversi app for android for my year 13 coursework and
Basically what I'm trying to do is generate an alphanumeric string, which is passed
Basically I want to know how to set center alignment for a cell using
Basically I have two models: User and Godfather. The godfather table has three columns:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.