Android Property Set android:nohistory= "true"

Source: Internet
Author: User

After setting android:nohistory= "true", the activity does not leave traces of history in the STATCK. The default value is False.

For example, suppose that there are three activity: a,b,c. These three activity can sequentially start the next activity, for example, a button in a, the user clicks to jump to B; Similarly, do a button in B and click Jump to C. c no longer does a button, just a demo shell activity.

The properties of configuration B in Androidmanifest.xml are: android:nohistory= "true"

The other two do not make special settings, only as a general activity processing.

It can be observed that after a is started, a jumps from a to B, then jumps from B to C, enters C, and if the return key is pressed, it will go directly to a, not to B. Simple Jump Logic route:

A–> b–> C–> Press the back key –> A

In conclusion, it is possible to understand the effect of android:nohistory= "true" on activity behavior: When the activity screen is not visible, it is equivalent to the finish () method of the Android system calling activity to end the activity.

Experiment Code:

A.java

1  Packagezhangphil.test;2 3 Importandroid.support.v7.app.ActionBarActivity;4 ImportAndroid.view.View;5 ImportAndroid.widget.Button;6 ImportAndroid.content.Context;7 Importandroid.content.Intent;8 ImportAndroid.os.Bundle;9 Ten  Public classAextendsactionbaractivity { One  A @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); the  -Button Button =NewButton ( This); -Button.settext ("Click to jump to B"); -         FinalContext context = This; +Button.setonclicklistener (NewView.onclicklistener () { -  + @Override A              Public voidOnClick (View v) { atIntent Intent =NewIntent (context, B.class); - startactivity (intent); -             } -         }); -          - Setcontentview (button); in     } -}

B.java

1  Packagezhangphil.test;2 3 Importandroid.support.v7.app.ActionBarActivity;4 ImportAndroid.view.View;5 ImportAndroid.widget.Button;6 ImportAndroid.content.Context;7 Importandroid.content.Intent;8 ImportAndroid.os.Bundle;9 Ten /** One * android:nohistory= "true" A  *  -  * */ -  the  Public classBextendsactionbaractivity { -  - @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); -          +Button Button =NewButton ( This); AButton.settext ("Click to jump to C"); at         FinalContext context = This; -Button.setonclicklistener (NewView.onclicklistener () { -  - @Override -              Public voidOnClick (View v) { -Intent Intent =NewIntent (context, C.class); in startactivity (intent); -             } to         }); +          - Setcontentview (button); the     } *}

C.java

1  Packagezhangphil.test;2 3 Importandroid.support.v7.app.ActionBarActivity;4 ImportAndroid.os.Bundle;5 6  Public classCextendsactionbaractivity {7 8 @Override9     protected voidonCreate (Bundle savedinstancestate) {Ten         Super. OnCreate (savedinstancestate); One     } A}

Androidmanifest.xml

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android"3  Package= "Zhangphil.test"4 Android:versioncode= "1"5 Android:versionname= "1.0" >6 7     <USES-SDK8         android:minsdkversion= "8"9 android:targetsdkversion= "All" />Ten  One     <Application A         Android:allowbackup= "true" - Android:icon= "@drawable/ic_launcher" - Android:label= "@string/app_name" the Android:theme= "@style/apptheme" > -         <Activity -              -             Android:name=". A " + Android:label= "A" > -             <Intent-filter> +                 <ActionAndroid:name= "Android.intent.action.MAIN" /> A  at                 <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> -             </Intent-filter> -         </Activity> -          -         <Activity -             android:nohistory= "true" in              - Android:name=". B " to Android:label= "B" > +         </Activity> -          the          <Activity *             Android:name=". C " $ Android:label= "C" >Panax Notoginseng         </Activity> -          the     </Application> +  A </Manifest>

(Go) Android Property set android:nohistory= "true"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.