0

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);
}
8
  • Have you added your activities to AndroidManifest.xml? Aug 17, 2017 at 13:36
  • Please show the manifest and that Activity code Aug 17, 2017 at 13:37
  • Add your FilesActivity onCreate here
    – Kapil G
    Aug 17, 2017 at 13:39
  • @cricket_007 here you go
    – murkr
    Aug 17, 2017 at 13:39
  • 1
    If you don't see your debug log, it is possible that setContentView() is crashing because your layout file doesn;t exist or is badly configured. TYou should see some error/crash when that happens. To check, try to call setContentView() with a known good layout resource (like one from one of your working activities). Aug 17, 2017 at 13:44

1 Answer 1

7

In FilesActivity override

protected void onCreate(Bundle savedInstanceState);

instead of

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.