Android parent activity - android

I have this in my manifest:
<activity
android:name=".PimMediaActivity"
android:hardwareAccelerated="true"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".SettingsActivity" />
</activity>
On my PimMediaActivity which has SettingsActivity declared as its parent in the manifest, I have a custom back button. There are cases like from push notification where I need to start the PimMediaActivity directly, but I want to be able to go back to the parent activity when the button is clicked. Is this feature only working with the ActionBar back button ?!

You should put this :
<activity
android:name=".PimMediaActivity"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:parentActivityName=".activities.SettingsActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".SettingsActivity" />
</activity>

Are you interested in retrieving the app state from before opening notification?
If no, you can just call startActivity(Intent) in onClick() method..

Related

using actionBar.setDisplayHomeAsUpEnabled in xml

I am writing this app and I seem to be calling actionBar.setDisplayHomeAsUpEnabled(true) in every Activity I create. I'm wondering if there is a way to set this value in the styles.xml or theme.xml; rather than repeating the same line of code every time.
Another way is you can declare in your AndroidManifest.xml
<activity
android:name=".CurrentActivity"
android:label="#string/title_activity_detailed_forecast"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.youpackage.name.appname.MainActivity" />
</activity>
CurrentActivity is your activity that you are in and MainActivity is your previous activity

android application does not show in the recent application tab

When i use the Label attribute in the manifest for an activity, it does not show in the recent application list. Code for activity in manifest file is:
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/MyTheme"
android:icon="#drawable/ic_launcher"
android:label=""
>
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
when i use android:label="#string/app_name" , then it start showing in the recent tab, but i dont want activity label.
Your application is not visible in recent apps list because label of your main activity is empty.
Change
<activity... android:label="">
To
<activity... android:label="#string/some_name">
Edit:
If you don't want to show label for your activity then do the following.
You must set android:label="#string/some_name" in <activity> tag
And then write getActionBar().setDisplayShowTitleEnabled(false); in onCreate() method of your activity you want to hide label of.
This will let you hide the activity label and will show your app in recent apps list as well.

Navigation Back to previous activity in android

I am trying to navigate back to previous activity with the UP back button in ActionBar but it doesn't work properly. I have
getActionBar().setDisplayHomeAsUpEnabled(true);
in
onCreate()
method and in
onOptionsItemSelected
I have
if(item.getItemId()==android.R.id.home){
onBackPressed();
}
On emulator it works fine. When i install the application on my mobile, then the back button is gone.
Any ideas how to fix that issue?
Part of my Manifest:
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<activity
android:name="datepicker.DatePicker"
android:label="#string/title_activity_date_picker" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
<activity
android:name="gridviewcontext.TableItem"
android:label="#string/title_activity_table_item" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
You have to add the parent activity name in the activity you enabled the back button in your manifest:
android:parentActivityName="your_parent_activity"
I am assuming that you are testing the app in a mobile with version less than API level 16.
If your app supports Android 4.0 and lower, include the Support Library with your app and add a element inside the <activity>. Then specify the parent activity as the value for android.support.PARENT_ACTIVITY, matching the android:parentActivityName attribute.Do as follows,
<activity
android:name="myomega.datepicker.DatePicker"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
in your manifest file, you are missing android:parentActivityName="com.example.myfirstapp.MainActivity" this line.
refererence http://developer.android.com/training/implementing-navigation/ancestral.html
Use finish() instead of onBackPressed()

all activity reverse when press back button

In my project I create several class and I am able to going from one activity to other , but the problem is when I press back menu all activity reversed I don't want that!!! below is manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bones.samples.android"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name" android:icon="#drawable/icon48x48" android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<activity android:label="#string/app_name" android:screenOrientation="landscape" android:name=".stage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="LevelOne" android:screenOrientation="landscape" ></activity>
<activity android:name="dialogue" android:theme="#android:style/Theme.Dialog" ></activity>
<activity android:name="FailDialogue" android:theme="#android:style/Theme.Dialog" ></activity>
<activity android:name="LevelTwo" android:screenOrientation="landscape" ></activity>
<activity android:name="LevelThree" android:screenOrientation="landscape" ></activity>
</application>
<uses-sdk android:minSdkVersion="10" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>
I want that when I am on leveltwo or dilogeue activity and press back button it directly go to stage activity but not in reverse all activities.
If you call one activity after another without calling finish, the activities are preserved in the back stack for further access.
If you dont want the activities to show up when the user presses back, keep calling finish method after calling the activity you want.
For Ex:-
Intent intent =new Intenet(this, NextActivity.class);
startActivity(intent);
finish();
This will close the current activity and will start the next activity. Now, when the user presses back, it will go the the activity earlier than this activity else, your application will close.
If you want to go to a specific activity, you can override the onBackPressed method and call a specific activity too.
Use:
YourActivity.this.finish()
after calling the intent to next activity, for all activities you dont want to display on BackPress.
if the above is not feasible, you can define the parent activity for up navigation:
Beginning in Android 4.1 (API level 16), you can declare the logical parent of each activity by specifying the android:parentActivityName attribute in the element.
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
This is what the Docs say
startActivity(CurrentActivity.this,NextActivity.class);
finish();
or
set flag on your manifest file
read below thread for more info
http://developer.android.com/guide/components/tasks-and-back-stack.html
or
Use fragment. u can replace the fragment . finally u can finish the activity.
Use this into Manifest...
android:noHistory="true"
as below...
<activity android:name="LevelOne" android:screenOrientation="landscape"
android:noHistory="true" ></activity>
<activity android:name="dialogue" android:theme="#android:style/Theme.Dialog"
android:noHistory="true" ></activity>
<activity android:name="FailDialogue" android:theme="#android:style/Theme.Dialog"
android:noHistory="true" ></activity>
This attribute will remove the current Activity from the Activity Stack when another Activity will start from this Activity...So, when you will press back button then it will not return to that previous Activity.

android application not closing

I am in trouble, I want to start my application from starting every time but it's not being.
When I exit from my application & come again. I found same activity which I have left before exit.
Now If I **shut down or switch off** my Android Device direct when my application is in foreground & then I **switch on device again**. I get same activity which I have left earlier. But I want to fresh application from login page. Because my setter & getter is null after switch on device, and I found all value null in my application.
My Manifest file is below:
<activity
android:name=".Main"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".screens.ScreenSplash"
android:screenOrientation="portrait" />
<activity android:name=".screens.LoginActivity" />
<activity
android:name=".screens.LoginActivity"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name=".screens.MainMenu"
android:configChanges="orientation|keyboardHidden" />
Kindly help me which is the problem & what should I do. Any help would be appreciated.
Add to your activity manifest
android:clearTaskOnLaunch="true"
According to your Manifest .Main is the launcher activity. so when your application is launched from icon tap then this is the first activity to display and rather if your application is not having any other activity on top of the stack.
so if you want to see the fresh login activity then make the login activity as launcher activity.
Maybe you want to try setting launchMode to standard?
http://developer.android.com/guide/topics/manifest/activity-element.html

Categories

Resources