AppcompatActivity Error with Android studio AppcompatActivity Error with Android studio android android

AppcompatActivity Error with Android studio


You have this issue because you are trying to use onCreate (Bundle savedInstanceState, PersistableBundle persistentState), but this method is available only from API level 21.

I am able to reproduce the issue with this sample code on Android 4.4:

public class TourActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState, new PersistableBundle());    }    @Override    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {        super.onCreate(savedInstanceState, persistentState);    }}

And the issue is resolved removing every occurrence of PersistableBundle:

public class TourActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);    }}

Check where you use PersistableBundle in your TourActivity and remove it or update your answer with the code of your activity.


Update your support library to 23 and your compileSdkVersion to 23 in build.gradle.

compileSdkVersion 23...compile 'com.android.support:support-v4:23.0.0'compile 'com.android.support:appcompat-v7:23.0.0'

Then sync your project with gradle files.

Also, Google Play Services is now 7.8.0


The problem is that your TourActivity is using a class available only from API level 21 PersistableBundle. The question here is why is doing that.

Remember you new activity have to inherit from AppCompatActivity as well.

Quick question, are you overriding public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) in the problematic activity? If you are doing it you probably are saving a reference to PersistableBundle which is not available in the device/emulator. Try removing it if you are not doing nothing there or comment it to try...