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 7035453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:18:22+00:00 2026-05-28T01:18:22+00:00

I have an Android app with a main tab activity, and several activities within

  • 0

I have an Android app with a main tab activity, and several activities within the individual tabs. In my main activity’s onCreate(), I have a runnable that creates a list, and in the individual activities, I make use of this list.

In the individual activities’s onCreate(), I also have Runnables that operate on the list. However, I need these Runnables to only run when the main tab activity’s Runnable completes creating the list, otherwise I’d get a null list. I’m trying to find an elegant way of doing this. Right now, in my main activity’s Runnable, I’m setting a global boolean variable isDone, and in my individual activity’s Runnable, I’m waiting for isDone to be set via a while loop. This works, but probably isn’t the best way of doing so.

Any thoughts?

Thanks.

Edit:
I’m trying the following code out, but I’m getting runtime errors:

In my MainActivity’s Runnable:

mainRunnable = new Runnable() {
  public void run() {
    try {
      generateList();
      synchronized(this) {
      listDone = true;
      notifyAll();
    }
  } catch (Exception e) {
      Log.e("BACKGROUND_PROC", e.getMessage());
    }
  }
};
Thread thread = new Thread(null, mainRunnable, "Background");
thread.start();

In my OtherActivity’s Runnable:

otherRunnable = new Runnable() {
  public void run() {
    synchronized(MainActivity.mainRunnable) {
      if (!MainActivity.getListDone()) {
        try {
          wait();
        } catch (InterruptedException e) {
        }
      }
    }
  }
};
Thread thread = new Thread(null, otherRunnable, "Background");
thread.start();

The mainRunnable seems to run completely, but the otherRunnable seems to cause the app to crash. I get the following error message:

01-10 15:41:25.543: E/WindowManager(7074): Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40539850 that was originally added here
01-10 15:41:25.543: E/WindowManager(7074): android.view.WindowLeaked: Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40539850 that was originally added here
  • 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-05-28T01:18:22+00:00Added an answer on May 28, 2026 at 1:18 am

    You can use the wait and notify methods.

    To do this, there needs to be some globally accessible object whose lock isn’t used by anything else in the program at this point in time. I’m assuming that the list-creating Runnable itself can play this role.

    So you could add something like this to the list-creating Runnable class:

    private boolean listsDone = false;
    
    boolean getListsDone() {
        return listsDone;
    }
    

    And something like this to its run() method, immediately after it’s done creating the lists:

    synchronized (this) {
        listsDone = true;
        notifyAll();
    }
    

    And something like this to the other Runnables’ run() methods, at the point where they need to wait:

    synchronized (listCreatingRunnableObject) {
        if (!listCreatingRunnableObject.getListsDone()) {
            try {
                listCreatingRunnableObject.wait();
            } catch (InterruptedException e) {
                // handle it somehow
            }
        }
    }
    

    Update: To clarify, both synchronized blocks need to be synchronized over the same object, and you have to call wait() and notifyAll() on that object. If the object is the Runnable, then it can be implicit for the first one (as in the above code), but if it’s the activity, you need to explicitly use the activity object in both cases.

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

Sidebar

Related Questions

In my Android app, I have a main activity that serves as an entry
well, I have my Android app that have 4 main options. For that I
I have an Android app with a ListActivity in the main view. The list
I have a class that extends android.app.Dialog, the layout is done in an xml
I have an Android project that branched into three different applications, app-1 , app-2
Here's the problem. In my app, I have 5 tabs which contains activities. In
I have android app that talks to server and syncs some data int SQLite
I have an Android app that I would like to convert to an Android
I have a tab layout app that needs to download a few files right
I have an android app that listens for json commands over a socket. I

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.