Android Primary Secondary summary

Source: Internet
Author: User

XML comment:

<!--comment Content--

You can no longer label the attributes inside the comment, outside the label.

Problem:

Appears in console:

You must restart ADB and Eclipse

Turn off Eclipse and simulator and kill Adb.exe this process, reboot

Activity interface

One of the four components

Three major elements:

1. Declaring a class to inherit activity

2. Associated Layout file (Setcontentview ())

3. Must be registered in the manifest file

<activity

Android:name = Package name + class name/>

Configuring the Portal interface in the manifest file

<intent-filter>

<action android:name= "Android.intent.action.MAIN"/>

<category android:name= "Android.intent.category.LAUNCHER"/>

</intent-filter>

Interface Jump:

Open an interface

Intent Intent = new Intent ();//intention: The bridge between interface communication

Intent.setclass (Mainactivity.this, Secondactivity.class);

Intent Intent = new Intent (mainactivity.this, Secondactivity.class);

StartActivity (Intent);

Close the interface

Finish ();

A----> B

Steps:

1. In a:

String string = Medittext.gettext (). toString (). Trim ();

Intent Intent = new Intent (mainactivity.this, Secondactivity.class);

Intent.putextra ("text", string);

Intent.putextra ("int", 1);

Intent.putextra ("Boolean", true);

StartActivity (Intent);

2, in B, oncreat ();

Get Intent

Intent Intent = Getintent ();

From intent or access to information

String Text = Intent.getstringextra ("text");

int i = Intent.getintextra ("int", 0);

Boolean Booleanextra = Intent.getbooleanextra ("boolean", false);

A----> B----> A

1. In a

String str = Medittext.gettext (). toString ();

Intent Intent = new Intent (this, secondactivity.class);

Intent.putextra ("str", str);

Startactivityforresult (Intent, 0);//Open an interface and wait for its return message

2. Return message in interface B

Intent data = new Intent ();

Data.putextra ("return", String);

Setresult (0, data);

Finish ();

3, a interface to receive messages and processing

Rewrite Onactivityresult ()

protected void Onactivityresult (int requestcode, int resultcode, Intent data) {

Super.onactivityresult (Requestcode, ResultCode, data);

if (data! = NULL)

{

String Stringextra = Data.getstringextra ("return");

Mtextview.settext (Stringextra);

}

}

Requestcode Request Code

Different request events for distinguishing between the current interface

ResultCode Result Code

Different return events used to differentiate the return message page

Note: Do not use the Devil number

Life cycle of activity

650) this.width=650; "Src=" http://note.youdao.com/yws/public/resource/95b3d57b16fcd617448e2ae0042f726d/ 628a41c32c1545fe8d7b651db121b646/acd880d015e842c4957aa255a9779f85 "style=" Border:none;line-height:1.5;height: auto; "alt=" acd880d015e842c4957aa255a9779f85 "/>

Create---Run

Oncreat ()-----> OnStart ()----> Onresume ()

Run---> Destroy

OnPause ()---> onStop ()----> OnDestroy ()

Run----> Pause (visible when not operational)

OnPause ()

To restore the running state:

Onresume ()

Run----> Stop (not visible and can be manipulated)

OnPause ()---"OnStop ()

Resume running:

Onrestart ()----"onStart ()----" Onresume

Note: When activity is paused or stopped, the current activity may be killed if the higher-priority process requires memory.

Memory: power-down disappears

External memory: Theoretically the data can be stored permanently

Generally save data in OnPause onStop OnDestroy (persistent)

oncreat OnStart Onresume to get the data back to the interface      


1. Get the data persisted path

String Path = "/mnt/sdcard/data.txt";

path of the//sdcard

String Path = environment.getexternalstoragedirectory () + "/data.txt";


2. Permissions:

If you need to use the system service, you should apply for permission .


//Read/write permissions for external storage (SDcard)

<uses-permission android:name= "Android.permission.READ_EXTERNAL_STORAGE"/>

<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>


3. Save data (usually in OnStop ())

4. Read data (generally in OnStart ())

FileInputStream FIS = null;

try {

FIS = new FileInputStream (path);

Bytearraybuffer ArrayBuffer = new Bytearraybuffer (5000);

int len = 0;

byte[] buffer = new byte[1024];

while ( -1! = (len = fis.read (buffer)))

{

Arraybuffer.append (buffer, 0, Len);

}

String str = new String (Arraybuffer.tobytearray (), 0,arraybuffer.length ());

Medittext.settext (str);

} catch (FileNotFoundException e) {

E.printstacktrace ();

} catch (IOException e) {

E.printstacktrace ();

}finally

{

if (FIS! = null)

{

try {

Fis.close ();

} catch (IOException e) {

TODO auto-generated Catch block

E.printstacktrace ();

}

}

}


Android Primary Secondary summary

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.