murkr murkr - 1 year ago 45
Android Question

android: Activity won't start

So, I have a menu with a few pictures and onClick, they open 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 clickt, a blank new page appears, with correct title, but - appearantly - without calling onCreate of the Activity.

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 liek 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);
}

Answer Source

In FilesActivity override

protected void onCreate(Bundle savedInstanceState);

instead of

protected void onCreate(Bundle savedInstanceState,  @Nullable PersistableBundle persistentState);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download