Thursday, February 6, 2014

android multithreaded UI can not be updated? ? Consult



public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
flv01 = (ListView) findViewById (R.id.flv01);
flv02 = (ListView) findViewById (R.id.flv02);
runable1 run1 = new runable1 ();
runable1 run2 = new runable1 ();
Thread thread1 = new Thread (run1);
Thread thread2 = new Thread (run1);
try {
thread1.start ();
thread1.join ();
thread2.start ();
thread2.join ();
} Catch (InterruptedException e1) {
/ / TODO Auto-generated catch block
e1.printStackTrace ();
}}


public class runable1 implements Runnable {
@ Override
public void run () {
System.out.println ("Local OK!!");
dbUtil_1 = new dbUtil ();
List > list3 = new ArrayList > ();
list3.clear ();
list3 = dbUtil_1.chakan (parameter 1);
System.out.println ("0000000" + list3);
adapter = new SimpleAdapter (
xiancheng.this,
list3,
R.layout.lv02,
new String [] {"biaoti"},
new int [] {R.id.stv00});
System.out.println ("Assignment" + list3);
flv01.post (new Runnable () {
public void run () {
flv01.setAdapter (adapter);
}});}}
public class runable2 implements Runnable {
@ Override
public void run () {
System.out.println ("Local OK!!");
dbUtil_1 = new dbUtil ();
List > list4 = new ArrayList > ();
list4.clear ();
list4 = dbUtil_1.chakan (parameter 2);
System.out.println ("0000000" + list4);
adapter = new SimpleAdapter (
xiancheng.this,
list4,
R.layout.lv02,
new String [] {"biaoti"},
new int [] {R.id.stv00});
flv02.post (new Runnable () {
public void run () {
flv02.setAdapter (adapter);
}});}}}



Red font print the results to the normal return value;

Then is:

Skipped 91 frames! The application may be doing too much work on its main thread.

Unable to get the value of the component, how does that matter children?

Reply:
adapter = new SimpleAdapter (
xiancheng.this,
list3,
R.layout.lv02,
new String [] {"biaoti"},
new int [] {R.id.stv00});
System.out.println ("Assignment" + list3);
flv01.post (new Runnable () {
public void run () {
flv01.setAdapter (adapter);

These operations do not put the child thread
Reply:
cited a floor yinke22222 reply:
adapter = new SimpleAdapter (
xiancheng.this,
list3,
R.layout.lv02,
new String [] {"biaoti"},
new int [] {R.id.stv00});
System.out.println ("Assignment" + l ......

No, android4.0 above involve access network portion must be in the child thread
Reply:
reference to the second floor qiaogn reply:
cited a floor yinke22222 reply: adapter = new SimpleAdapter (
xiancheng.this,
list3,
R.layout.lv02,
new String [] {"biaoti"},
new int [] {R.id.stv00});
Syst ......


What I mean is only part of the network operator to put the child thread
Reply:
thread1.start ();
thread1.join ();
This is what is meant by Why start a thread after a would go join again?
Reply:
flv02.setAdapter (adapter); thread which can not have such a ui operation, go to handler
Reply:
Use Handler Interface ah refresh
Reply:
1, the main thread can not join the child thread. The purpose is to open the child thread running slowly time-consuming operation, the main thread to return as soon as possible.
2, sub-refresh UI thread with postInvalidate or Handler.
Reply:
是, join problems, teachable, and thank you
Reply:
reference to the 7th floor flyingghost reply:
1, the main thread can not join the child thread. The purpose is to open the child thread running slowly time-consuming operation, the main thread to return as soon as possible.
2, sub-refresh UI thread with postInvalidate or Handler.


Why not join, the main thread waits for the child thread UI obstruction caused by the end of it?

No comments:

Post a Comment