A few seconds later, the advertisement came back, but the following error occurred, but the handler could not be passed in. Depressed. Does anyone know how to solve this problem?
06-30 09:26:50. 799: Error/androidruntime (1134): Fatal exception: servicethread
06-30 09:26:50. 799: Error/androidruntime (1134): Android. View. viewroot $ calledfromwrongthreadexception: only the original thread that created a view hierarchy can touch its views.
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. viewroot. checkthread (viewroot. Java: 2954)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. viewroot. requestlayout (viewroot. Java: 645)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. requestlayout (view. Java: 8397)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. requestlayout (view. Java: 8397)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. requestlayout (view. Java: 8397)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. requestlayout (view. Java: 8397)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. requestlayout (view. Java: 8397)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. widget. relativelayout. requestlayout (relativelayout. Java: 257)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. requestlayout (view. Java: 8397)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. setflags (view. Java: 4690)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. View. View. setvisibility (view. Java: 3165)
06-30 09:26:50. 799: Error/androidruntime (1134): at D. Q (unknown source)
06-30 09:26:50. 799: Error/androidruntime (1134): at C. onpostexecute (unknown source)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. OS. asynctask. Finish (asynctask. Java: 417)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. OS. asynctask. Access $300 (asynctask. Java: 127)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. OS. asynctask $ internalhandler. handlemessage (asynctask. Java: 429)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. OS. handler. dispatchmessage (handler. Java: 99)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. OS. login. loop (login. Java: 123)
06-30 09:26:50. 799: Error/androidruntime (1134): at Android. OS. handlerthread. Run (handlerthread. Java: 60)
Method of thinking in bed in the morning: (tested and feasible)
1. Create an adview in oncreate of the activity.
// Create the adview
// Please replace my_banner_unit_id with your AdMob publisher ID
Madview = new adview (this, adsize. Banner, my_banner_unit_id );
Madview. setadlistener (this );
// Initiate a generic request to load it with an ad
Adrequest ad = new adrequest ();
Madview. loadad (AD );
2. Let the activity implement the interface (implements adlistener)
3. Use handler in onreceivead to refresh the page
@ Override
Public void onreceivead (AD arg0 ){
If (handler! = NULL ){
Handler. sendemptymessage (ads_incomming );
}
}
4. Of course, you have to process the message in handler:
Private handler = new handler (){
@ Override
Public void handlemessage (Message MSG ){
Switch (msg. What ){
Case ads_comming :{
Root. addview (madview, new linearlayout. layoutparams (linearlayout. layoutparams. fill_parent,
Linearlayout. layoutparams. wrap_content ));
Break;
}
}
}
The root is the Root View on acitivity, that is
@ Override
Protected void oncreate (bundle savedinstancestate)
{
...
...
...
Setcontentview (Root );
There is also the creation of adview in 1.
}
In addition, for information about the inability to display advertisements, see the following post:
Analyze why AdMob does not display advertisements in China