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

  • Home
  • SEARCH
  • 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 8584271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:44:05+00:00 2026-06-11T21:44:05+00:00

In my MainActivity I have a class initialization like so: Presentation presentation = new

  • 0

In my MainActivity I have a class initialization like so:

Presentation presentation = new Presentation("link");

Presentation is a class which gets initialized using values from a .JSON file on a web server:

public Presentation(String URL) {
    // Do stuff
    doNetworking();
}
private doNetworking() {
    // Network access here
    // This throws the Network on Main Thread exception
}

In my MainActivity, I need all the values of Presentation to be there in the next step:

Presentation presentation = new Presentation();
// Do some stuff with it

Using the AsyncTask I am not sure how I should go about doing this, so far I have something like this:
public Presentation(String URL) {
// Do stuff
new InitializePresentation().execute(URL);
}

private class InitializePresentation extends AsyncTask<String, Void, Boolean> {
    // Amongst other things
    protected Boolean doInBackground(String... params) {
        // Do the networking stuff here
    }
}

What I need is to refactor this code so that it is asynchroneous but behaves like a synchroneous call. Any help is greatly appreciated.

edit
How does one refactor a code to accomplish this?

Bitmap b = new Bitmap();
Load bitmap from network;
Use bitmap in imageview;

Can this be used in this fashion? Or do I have to use it like

Async, doInBackground() {
   Load bitmap from network
   Use bitmap in imageview
   Continue with application
}

Thank you!

  • 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-11T21:44:07+00:00Added an answer on June 11, 2026 at 9:44 pm

    You can show a progress dialog while doing the network stuff:

    private ProgressDialog progressDialog;
    private Context context;
    
    public InitializePresentation (Context context) {
        this.context = context;
    }
    
    @Override
    protected void onPreExecute() {
        progressDialog = ProgressDialog.show(context, "", "loading", true);
    }
    
    /* 
     * @see android.os.AsyncTask#doInBackground(Params[])
     */
    @Override
    protected String doInBackground(String... arg0) {
        // Do the networking stuff here
    }
    
    @Override
    protected void onPostExecute(final String result) {
        progressDialog.dismiss();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity ( MainActivity.java ) in which content view is like this
I have TabActivityGroup: MainActivity class contain some tab, that name loading from db. Sales,
I have Mainactivity which extend FragmentActivity ,I am loading fragment in layout using LinearLayout
I have a mapview class which extends MapActivity. The code i'm using follows the
If I have a string variable inside one class MainActivity.selectedFilePath which has a value
I have 2 tabs, named : Tab1, Tab2 class MainActivity extends TabActivity. MainActivity.java public
I have this situation where i have to start an activity from my mainActivity.
My Application has 3 activities (MainActivity,SampleActivity,TempActivity) and Application have to start from MainActivity because
on MainActivity.java I have host.addTab(host.newTabSpec(Map) .setIndicator(Map, getResources().getDrawable(R.drawable.icon_user)) .setContent(new Intent(this, Map.class))); On Map.Java public class
I have following code that displays an Image with letters, public class MainActivity extends

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.