Ir al contenido principal

Android - Basic Steps (Intent)

Application Components

  • Activity
    • Primary class for user interaction
    • Provide the GUI
  • Main 3 components
    • Services - Support ground back operations
      • Support interaction with remote processes
    • BroadcastReceiver - Responds to an event on the device
      • An example is the sms
    • ContentProvider - Allow to share data among applications
      • Uses database-style inferface

Building an App


  • The activity order is established in the task backstack
  • The activity lifecycle
    • Resumed / Running
    • Paused
    • Stopped
  • Methods for an activity
    • onCreate
    • onStart - when the app become visible
    • onResume - when is able to interact with the user
    • onPause
    • onStop - when the app become invisible
    • onDestroy - in not called when android kill the app by the lack of memory
    • onRestart - when the user press back and show the previous activity

Invoke and activity

  • startActivity
  • startActivityForResult
    • When this method is used, override the method onActivityResut()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK
&& requestCode == PICK_CONTACT_REQUEST) {
               }
          }


Tips

  • To avoid Resume the activity when change from vertical to landscape position change the configuration in the AndroidManifest file.
In the AndroidManifest.xml inside the tags; <application> , <activity>. Add the line
android:configChanges="orientation|keyboardHidden|screenSize"

Intents


  • Data Structure that represents 
    • Operation to be performed (Select a contact, dial a phone number)
    • Event that has ocurred

Intent Field

  • Action
  • Data
  • Category
  • Type
    • Ex: IMAGE/*, IMAGE/PNG, IMAGE/JPG, TEXT/HTML
  • Component
  • Extra 
  • Flag

Actions

  • ACTION_DIAL
    • Ex:  Intent intent = new Intent(Intent.ACTION_DIAL);
  • ACTION_EDIT - Display data to edit
  • ACTION_SYNC - Synchonize device data with server
  • ACTION_MAIN - Starts an initial activity of app

Data

  • To pass data to an Intent is through an URI
    • Ex: Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+55555"));

Category

  • Additional information that can handle the intent
    • CATEGORY_BROWSER
    • CATEGORY_LAUNCHER - Initial activity of a task & is listed in the top-level app launcher

Type

  • Define the type of the information
    • Intent.setType(String type)
    • Intent.setDataAndType(Uri data, String type)

Component

  • Used when there is only one component that should receive the intent
    • Intent intent = new Intent( Context packageContext, Class<?> cls)
    • setComponent()
    • setClassName()
    • setClass()

Extra

  • Add extra information in a Map form (Key-value pairs)
    • Intent.EXTRA_EMAIL
  • to set extra data depends of the intent

Flag

  • Show how the intent has to handle
    • FLAG_ACTIVITY_NO_HISTORY -this does not put the activity in the History Stack
    • FLAG_DEBUG_LOG_RESOLUTION - this show more logging information when the intent is processed

Invoke another activity

  • Directly
    • Intent helloAndroidIntent = new Intent(Context packageContext, Class<?> cls)
  • Indirectly
    • In this case Android, only compare with the available applications that match in:
      • Action
      • Data (Type & URI)
      • Category
    • Can specified in the AndroidManifest.xml, including the data
<activity>
  <intent-filter>
       .....
       <action android:name="android.intent.action.DIAL" />
       <category android:name="android.intent.category.DEFAULT" />
       .....
  </intent-filter>
  <data
     android:mimeType="string"
     android:scheme="string"
     android:host="string"
     android:port="string"
     android:path="string"
     android:pathPattern="string"
     android:pathPrefix="string"
  />
</activity>

Invoke activity from another application

  • Invoker application
    • In the Activity call the other activity using startActivity() method
      • startActivity(new Intent(ACTIVITY_OTHER_APP));
      • ACTIVITY_OTHER_APP - is the activity defined in the AndroidManifest in the other app
  • Calling application
    • In the AndroidManifest define the <intent-filter> to link the activity to be called.
    <activity>
        <intent-filter>
                      <action android:name="ACTIVITY_OTHER_APP" />
                      <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

      Comentarios

      Entradas populares de este blog

      Android - Basic Steps (Service)

      Service Run in the main thread of the hosting application Android can kill the Service if need the resources Purpose Supporting inter-application method execution Performing background processing Start a Service Call Context.startService(Intent intent)\ To call from a Fragment use getActivity().getApplicationContext().startService( intentService); Executing the service After call startService(...)  In the Service is executed the method onStartCommand(...) If the method returns the constant START_NOT_STICKY then Android will not restart the service automatically if the the process is killedp Foreground To execute the service foreground call the method startForeground() Use this if the user is aware of the process Bind to a Service Call the method Context.bindService( Intent service ServiceConnection con int flags ) Send Toast from the Service On the method onStartCommand receive the message   ...

      BI - SSIS ( Basics I )

      SSIS - Basic Concepts Tasks Bulk Insert Task—Loads data into a table by using the BULK INSERT SQL command. Data Flow Task—This is the most important task that loads and transforms data into an OLE DB Destination. Execute Package Task—Enables you to execute a package from within a package, making your SSIS packages modular. Execute Process Task—Executes a program external to your package, like one to split your extract file into many files before processing the individual files. Execute SQL Task—Executes a SQL statement or stored procedure. File System Task—This task can handle directory operations like creating, renaming, or deleting a directory. It can also manage file operations like moving, copying, or deleting files. FTP Task—Sends or receives files from an FTP site. Script Task—Runs a set of VB.NET or C# coding inside a Visual Studio environment. Send Mail Task—Sends a mail message through SMTP. Analysis Services Processing Task—This task processes a SQL Server A...

      TOGAF9

      Kinds of Architectures Business Architecture / Business Process Architecture    Define the business strategy, governance, organization and key business processes Data Architecture    Describe the structure of an organization logical and physical data assets and data resources Application Architecture    Describe a blueprint for the individual application systems to be deploy, interactions and  their relationships to the core business processes of the organization Technology Architecture    Describe the logical software and hardware capabilities that are required to support the deployment of business data and application services. This includes middle-ware infrastructure, networks, communications, processing standards  Architecture Governance Increase transparency of accountability, and informed delegation of authority Controlled risk management Protection of the existing asset base through maximizing  re-us...