I'm trying to launch an activity from preference-header.
I searched a lot for a solution but didn't find except this question :Start activity from preference-headers.
but when applying its answer I got a new Exception :
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.package.myapp/com.package.myapp.MyActivity}; have you declared this activity in your AndroidManifest.xml?
This is my code:
<header
android:icon="@drawable/ic_contacts"
android:title="@string/menuOptionContact">
<intent android:targetPackage="com.package.myapp"
android:targetClass="com.package.myapp.MyActivity" />
</header>
I tried to change the code to many forms like this:
android:targetClass="MyActivity"
Or
android:targetClass=".MyActivity"
all gave me same Exception
I tried to start it from inside the corresponding fragment like this :
<header
android:fragment="com.package.myapp.SettingsActivity$ContactPreferenceFragment"
android:icon="@drawable/ic_contacts"
android:title="@string/menuOptionContact">
</header>
and inside my fragments onCreate I put :
startActivity(new Intent(getActivity(), MyActivity.class));
it launches the activity but when I tap back from MyActivity it takes me to a blank fragment then I have to tap back again to go back to SettingsActivity
How can I launch MyActivity directly from preference-header or get rid of the blank fragments in back tap?
Edit
My AndroidManifest.xml
:
<activity
android:name=".MyActivity"
android:label="@string/app_name">
</activity>
any help will be very appreciated