Admob In Android. How To Make It Appear And Disappear
I am new to programming in android. I have followed instruction and create a admob banner. How can I make it appear at certain intervals, and make it disappear if I want to? For ex
Solution 1:
- You don't have to call
AsyncTask.doInBackground
, this method will be called by AsyncTask itself. AsyncTask.doInBackground
is called in other thread instead of UI thread, you may not want to start an animation in it, that will cause some problems on UI.- There are lots of ways that you can make the view appear and disappear with intervals, using AsyncTask is not one of them, I think. Following is sample code which use Handler to archive this.
public MyActivity extends Activity {
private static final int SHOW = 1;
private static final int HIDE = -1;
private View adView;
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
adView.setVisibility(msg.what);
}
}
private void startTriggerThread() {
new Thread() {
boolean show = false;
public void run() {
while (true) {
if (show) {
handler.sendEmptyMessage(View.GONE);
} else {
handler.sendEmptyMessage(View.VISIBLE);
}
show = !show;
try {
Thread.sleep(INTERVALS);
}
catch (InterruptException e) {
// Ignore.
}
}
}
}.start();
}
// Other methods
}
Post a Comment for "Admob In Android. How To Make It Appear And Disappear"