murkr
murkr

Reputation: 694

android: Activity won't start

So, I have a menu with a few pictures and an onClick method which opens a new page. That works for all menu items except one. That one is written in exactly the same way as the rest, but when the menu item is clicked, a blank new page appears, with correct title, but - apparently - without calling onCreate method of the new activity.

There are no error messages either.

The code, where the Activitys are started:

public void onClick(View v) {

    Intent intent = null;
    Context context = v.getContext();

    switch(position) {
        case 0:
            intent = new Intent(context, BooksActivity.class);                     
            break;
        case 1:
            intent = new Intent(context, GamesActivity.class);
            break;
        case 2:
            intent = new Intent(context, MusicActivity.class);
            break;
        case 3:
            intent = new Intent(context, FilesActivity.class);
            break;
        case 4:
            intent = new Intent(context, VideosActivity.class);
            break;
    }
    context.startActivity(intent);            
}

Works like a charm for every activity but FilesActivity. In the FilesActivity.onCreate method, I print a log:

Log.d(TAG, "initialized");

but that log is never shown.

Any idea what is going on here?

Edit: All activities are added to the manifest in the same way:

<activity
    android:name=".MusicActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/title_activity_music"
    android:parentActivityName=".MainActivity"
    android:theme="@style/FullscreenTheme">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.wilzek.hoerstift.MainActivity" />
</activity>
<activity
    android:name=".FilesActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/title_activity_files"
    android:parentActivityName=".MainActivity"
    android:theme="@style/FullscreenTheme">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.wilzek.hoerstift.MainActivity" />
</activity>

Edit: Files.Activity onCreate:

public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
    super.onCreate(savedInstanceState, persistentState);
    setContentView(R.layout.activity_files);
    Log.e(TAG, "INITIALIZED");

    listView = (ListView)findViewById(R.id.files_list);
    listView.setOnItemClickListener(onItemClickListener);

    try {
        files = Arrays.asList(USBCommunicationManager.getRootDir().listFiles());
        Log.e(TAG, "Root Dateien: " + files.size());
    } catch (Exception e) {
        Log.e(TAG, "Root Dateien konnten nicht gefetcht werden. Yay denglish.");
    }

    filesAdapter = new FilesAdapter(this, files);
    listView.setAdapter(filesAdapter);
}

Upvotes: 0

Views: 1678

Answers (1)

Juan
Juan

Reputation: 5589

In FilesActivity override

protected void onCreate(Bundle savedInstanceState);

instead of

protected void onCreate(Bundle savedInstanceState,  @Nullable PersistableBundle persistentState);

Upvotes: 7

Related Questions