I am starting to build my first app from developer.android.com. Recently switched to Android Studio and found that I can't set the hierarchical parent for the new activity (DisplayMessageActivity). It states "Hierarchical Parent must already exist". Can someone please guide me on this? In Eclipse, it works fine.
Declare a Parent Activity You can do this in the app manifest, by setting an android:parentActivityName attribute. The android:parentActivityName attribute was introduced in Android 4.1 (API level 16). To support devices with older versions of Android, define a <meta-data> name-value pair, where the name is "android.
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
Intent data = new Intent(); data. putExtra("myData1", "Data 1 value"); data. putExtra("myData2", "Data 2 value"); // Activity finished ok, return the data setResult(RESULT_OK, data); finish();
Explanation. Generally, every activity is having its UI(Layout). But if a developer wants to create an activity without UI, he can do it.
I was also doing the My First App tutorial on the Android Developer website using Android Studio and experienced this same problem. Thanks to charmarel for the tip that Android Studio will allow you to leave the problematic field blank. However, this will cause you do some of the legwork that the IDE would otherwise do for you in order to have the app properly running.
The workaround is not all that bad:
Edit the new Activity node to include this information, it should look like this:
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
That's it, issue circumnavigated!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With