Activity(2018.5.4)

Start an Activity

General start

  startActivity(Intent intent)

Startup with callback

   startActivityForResult(intreqCode, Intent intent)

   onActivityResult(intreqCode, intresultCode, Intent data)

How to carry extra data

  intent.putExtra(name, value)

How to get the extra data carried

  Xxxintent.getXxxExtra(name)

How to get the activation intent

  Intent getIntent ()

end an Activity

General end

  finish()

end with result

   setResult(intresultCode, Intent data)

  finish()

————————————————————————————————————————————————————

Four states of Activity interface

Running status : visible and operational
Paused state : visible but not actionable
Stopped state : not visible, but object exists
Dead state : the object does not exist

Activity 's lifecycle callback method

onCreate ()
onStart ()
onResume ()
onPause ()
onRestart ()
onStop ()
onDestory ()

Activity life cycle diagram


test case

1 ) Interface from " Dead " --> " Run "

   -->

2) Interface from " Run " --> " Death "

   -->

3) The interface is from " Run " --> " Stop "

   -->

4) Interface from " Stop " --> " Run "

   -->

5) Interface from " Run " --> " Pause "

   -->

6) The interface changes from " Pause " --> " Run "

   -->


Activity life cycle and state


————————————————————————————————————————————————————

ActivityTaskStack

In Android , the system uses the Task Stack (Back Stack) structure to store and manage the Activity objects that are started
• When an application is started , the system will create a corresponding Task Stack for it to store and manage the application's Activity objects
• Only the Activity at the top of the top task stack can be displayed in the window


ActivitylaunchMode

In Android , starting an Activity sometimes requires always creating a new object , sometimes reusing an existing object , which can be specified through the launchMode property when configuring the activity
The launchMode attribute values ​​( 4 ) are :
standard :
Standard mode, a new instance is generated each time the startActivity () method is called.
singleTop :
If there is already an instance at the top of the Activity stack, no new instance will be generated; if it is not at the top of the stack, a new instance will be generated.
singleTask :
There is only one instance , by default in the current Task
singleInstance :
There is only one instance , a new stack will be created when it is created , and there can be no other objects in this stack

application exercises

Intent to enter the phone dialing interface : Intent.ACTION_DIAL
Intent to enter the SMS editing interface : Intent.ACTION_SENDTO
Intent to make a call : Intent.ACTION_CALL
Tool class for sending SMS : SmsManager
Required permissions :

  Call permission : android.permission.CALL_PHONE

  Permission to send text messages : android.permission.SEND_SMS

Uri for calling : tel:110
Enter the phone Uri of the SMS interface: smsto:110
The identifier carrying additional SMS data is named : sms_body

————————————————————————————————————————————————————

Four ways to set up monitoring

1. In layout: android:onClick="method name"

        In Activity: public void method name (View V) { }

  2.view.setOnClickListener(new View.OnClickListence(){})   

3.view.setOnclickListenter(this)

4.view.setOnclickLListenter(onclicklistenter member variable)


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325795907&siteId=291194637