Question

If in the main activity, android.os.Handler is passed from a constructor to a new thread. Can...

If in the main activity, android.os.Handler is passed from a constructor to a new thread. Can that new thread access view object? Can it post to the handler?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If in the main activity, android.os.Handler is passed from a constructor to a new thread. Can that new thread access view object? Can it post to the handler?

  • Yes, the new thread can access the view object as we can synchronize the main thread which will reduce the restriction and complexity of the threads and will provide us with the additional constructed classes for handling concurrently.
  • The handler will allow communicating back with the user interface from the new thread in the background and then the handler will allow us to send and process the message and the runnable objects.
  • Later on, the handler can be made use to schedule messages and the runnable for executing at the same point in the future or can be made use of the same thread in mere future.
  • It can also be used to enqueue the action to be performed on the different or new thread which is been made concurrently.

Hence, this is how the android.os.Handler will be useful to view objects.

Add a comment
Know the answer?
Add Answer to:
If in the main activity, android.os.Handler is passed from a constructor to a new thread. Can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • Problem 3: (15 pts) Modify the Patient class with two overloaded constructors: A new default constructor...

    Problem 3: (15 pts) Modify the Patient class with two overloaded constructors: A new default constructor which initializes the data items for a patient object using code within the constructor (use any data). A second constructor with parameters to pass all the data items into the object at the time of instantiation. Create a test main class which instantiates two objects. Instantiate the first object using the default constructor and the second object using the constructor with the parameters.

  • Consider the following codes: public class TestThread extends Thread {     public static void main(String[] args)...

    Consider the following codes: public class TestThread extends Thread {     public static void main(String[] args) {         TestThread thread = new TestThread();     }     @Override     public void run() {         printMyName();     }     private void printMyName() {         System.out.println("Thread is running");     } } Test Stem / Question Choices 1: What method should you invoke to start the thread TestThread? A: start() B: run() C: No. Thread will run automatically when executed. D: TestThread is not...

  • Start a new thread. Identify a disease of your choice. Provide a brief overview of the...

    Start a new thread. Identify a disease of your choice. Provide a brief overview of the disease (who it affects, the seriousness of the disease, cost to society, a cause of the disease), classification of the disease, means of spreading (use the chain of infection model if appropriate), means of prevention, and a prediction for eradicating the disease. Reply to at least one other post. You may ask follow-up questions, provide additional information that you may be aware of, or...

  • 1. public class Threads5 { 2. public static void main (String[l args) 3. new Thread(new Runnable()...

    1. public class Threads5 { 2. public static void main (String[l args) 3. new Thread(new Runnable() 4. public void run() 5. System.out.print("bar"); 6. start(; 7 What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes normally and prints "bar". D. The code executes normally, but nothing prints

  • Create a new thread for your post and, in a single post, respond to each of...

    Create a new thread for your post and, in a single post, respond to each of the following questions: Why is the theory of charisma described as a double edged sword? Please share at least 2 examples of this and explain why. How does Transformational Leadership differ from Charismatic Leadership? What are at least 2 examples of Transformational Leaders and explain why? 450 words

  • QUESTION 13 A constructor is the same as any other method definition EXCEPT for what? A...

    QUESTION 13 A constructor is the same as any other method definition EXCEPT for what? A constructor includes an optional argument list. A constructor includes an optional access modifier, usually public. A constructor includes a return type. A constructor places arguments within parentheses (). 2 points    QUESTION 14 Using the asterisk wildcard (e.g. import com.packageName.*) will include all of the classes within packageName, even if they aren’t used. True False 2 points    QUESTION 15 The Random class gives...

  • I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation...

    I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation problem: at EvenOdd.main(EvenOdd.java:10) I am unable to find what I can do to fix this issue. Can you please assist? My code is below: import java.util.InputMismatchException; import java.util.Scanner; public class EvenOdd {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);        System.out.println("Welcome to this Odd program!");        int userInput1 = input.nextInt();    }       public...

  • Create a new thread. Identify a community organizing topic/issue of your choice. One example might be...

    Create a new thread. Identify a community organizing topic/issue of your choice. One example might be “no smoking in public places.” Then, assign a role to yourself such as health educator, a tobacco farmer, avid smoker, avid nonsmoker, a retailer who sells tobacco, a restaurant owner, or any other role that might be interesting. Provide a brief summary from your point of view on the issue (based on the role you choose). What is your position on the topic/issue, and...

  • Please Help! I need to update the code below to meet these criteria! 1. The constructor...

    Please Help! I need to update the code below to meet these criteria! 1. The constructor of die class initializes face of Die to 3 2. roll method updates face of die to value from 1-6 3. getFace() method provides current face to the main program 4. main create a Die object 5. main create a Die object 6. main rolls die 5 times 7. main computes sum of rolls 8. main computes actual average of the rolls <--------- Code...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT