Pr4isethesun
Pr4isethesun

Reputation: 31

android: cannot find symbol TaskDescription

I am trying to set the color of the ActionBar while my app is "minimized" using the TaskDescription as suggested by the answer to this post: Setting header color of app in overview (recent apps) screen

Here is the relevant code:

...
import android.app.ActivityManager;
...
public class MainActivity extends SherlockFragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
...
        int c = Color.parseColor("#0A782F");
        ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(R.string.app_name, R.drawable.launcher, c);
        ((SherlockFragmentActivity) this).setTaskDescription(td);
    }
...
}

Although I have not posted the xml resource files for this project, you may assume that R.string.app_name and R.drawable.launcher are defined in xml files.

Here's the problem: when I compile this code, I get the following error:

error: cannot find symbol
...
symbol: class TaskDescription
location: class MainActivity

Now, from what I understand, Java throws the cannot find symbol error when you refer to a class or variable name that does not exist. In the case of classes, it is usually caused by forgetting to import the class you need. However, that cannot be the cause in this case, as I have clearly imported ActivityManager at the top of my class file.

Here are some other examples where people have done exactly the same things, just to show that I have done my research: http://www.programcreek.com/java-api-examples/index.php?class=android.app.ActivityManager&method=TaskDescription

Finally, I thought the problem might have been that you can only instantiate the TaskDescription class in an Activity context. However, I am using SherlockFragmentActivity instead of the standard AppCompatActivity. Unfortunately, I tried changing this and I still get the same error. Any ideas?

Thanks in advance for your help!

Upvotes: 0

Views: 918

Answers (1)

Pr4isethesun
Pr4isethesun

Reputation: 31

Found the solution! I didn't mention in the problem that I had built my project using gradle. The issue was that I was using an old Sdk version (in particular, I was using a version of the android Sdk which had not yet defined the TaskDescription class). Therefore, to fix the problem, all I had to do was add the following line to the appropriate place in my build.gradle file:

compileSdkVersion 21

Hope this helps someone else who is feeling lost for the same reason.

Upvotes: 1

Related Questions