Reputation: 59
I want to hide title bar no matter is it in background or foreground. I've just tried this code but had error.Can somebody say what's wrong with my code?
This is error:
FATAL EXCEPTION: AsyncTask #1
Process: com.example.amadey.myapplication3, PID: 21769
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:249)
at android.app.Activity.requestWindowFeature(Activity.java:3298)
at com.example.amadey.myapplication3.Activity$AsyncCaller.doInBackground(Activity.java:31)
at com.example.amadey.myapplication3.Activity$AsyncCaller.doInBackground(Activity.java:28)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
My code:
public class Activity extends Activity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
new AsyncCaller().execute();
}
private class AsyncCaller extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Activity.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
return null;
}
}
}
Upvotes: 0
Views: 47
Reputation: 1499
You cannot perform UI action in any thread except in main UI thread.
Activity.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this line has to be in onCreate()
method of your Activity
class.
Also, you better change the name of your activity.
Upvotes: 1
Reputation: 93678
You can't call requestWindowFeature after you call setContentView. It has to be called before. And it shouldn't be called from an AsyncTask at all.
Upvotes: 2