Showing posts with label Apps. Show all posts
Showing posts with label Apps. Show all posts
Android - Application Components

Android - Application Components

Application components are the essential building blocks of an Android application. These components are loosely coupled by the application manifest file AndroidManifest.xml that describes each component of the application and how they interact.
There are following four main components that can be used within an Android application:
ComponentsDescription
ActivitiesThey dictate the UI and handle the user interaction to the smart phone screen
ServicesThey handle background processing associated with an application.
Broadcast ReceiversThey handle communication between Android OS and applications.
Content ProvidersThey handle data and database management issues.

Activities

An activity represents a single screen with a user interface,in-short Activity performs actions on the screen. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. If an application has more than one activity, then one of them should be marked as the activity that is presented when the application is launched.
An activity is implemented as a subclass of Activity class as follows −
public class MainActivity extends Activity {

}

Services

A service is a component that runs in the background to perform long-running operations. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity.
A service is implemented as a subclass of Service class as follows −
public class MyService extends Service {

}

Broadcast Receivers

Broadcast Receivers simply respond to broadcast messages from other applications or from the system. For example, applications can also initiate broadcasts to let other applications know that some data has been downloaded to the device and is available for them to use, so this is broadcast receiver who will intercept this communication and will initiate appropriate action.
A broadcast receiver is implemented as a subclass of BroadcastReceiverclass and each message is broadcaster as an Intent object.
public class MyReceiver  extends  BroadcastReceiver {

public void onReceive(context,intent){}

}

Content Providers

A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolverclass. The data may be stored in the file system, the database or somewhere else entirely.
A content provider is implemented as a subclass of ContentProvider class and must implement a standard set of APIs that enable other applications to perform transactions.
public class MyContentProvider extends  ContentProvider {

public void onCreate(){}

}
We will go through these tags in detail while covering application components in individual chapters.

Additional Components

There are additional components which will be used in the construction of above mentioned entities, their logic, and wiring between them. These components are −
ComponentsDescription
FragmentsRepresents a portion of user interface in an Activity.
ViewsUI elements that are drawn on-screen including buttons, lists forms etc.
LayoutsView hierarchies that control screen format and appearance of the views.
IntentsMessages wiring components together.
ResourcesExternal elements, such as strings, constants and drawable pictures.
ManifestConfiguration file for the application.

Computer - Applications

Following list demonstrates various applications of computers in today's arena.

Business

A computer has high speed of calculation, diligence, accuracy, reliability, or versatility which made it an integrated part in all business organisations.
Computer is used in business organisations for:
  • Payroll calculations
  • Budgeting
  • Sales analysis
  • Financial forecasting
  • Managing employees database
  • Maintenance of stocks etc.



Banking

Today banking is almost totally dependent on computer.
Banks provide following facilities:
  • Banks provide online accounting facility, which includes current balances, deposits, overdrafts, interest charges, shares, and trustee records.
  • ATM machines are making it even easier for customers to deal with banks.


Insurance

Insurance companies are keeping all records up-to-date with the help of computers. The insurance companies, finance houses and stock broking firms are widely using computers for their concerns.
Insurance companies are maintaining a database of all clients with information showing
  • procedure to continue with policies
  • starting date of the policies
  • next due installment of a policy
  • maturity date
  • interests due
  • survival benefits
  • bonus



Education

The computer has provided a lot of facilities in the education system.
  • The computer provides a tool in the education system known as CBE (Computer Based Education).
  • CBE involves control, delivery, and evaluation of learning.
  • The computer education is rapidly increasing the graph of number of computer students.
  • There are number of methods in which educational institutions can use computer to educate the students.
  • It is used to prepare a database about performance of a student and analysis is carried out on this basis.

Marketing

In marketing, uses of computer are following:
  • Advertising - With computers, advertising professionals create art and graphics, write and revise copy, and print and disseminate ads with the goal of selling more products.
  • At Home Shopping - Home shopping has been made possible through use of computerised catalogues that provide access to product information and permit direct entry of orders to be filled by the customers.


Health Care

Computers have become important part in hospitals, labs, and dispensaries. The computers are being used in hospitals to keep the record of patients and medicines. It is also used in scanning and diagnosing different diseases. ECG, EEG, Ultrasounds and CT Scans etc., are also done by computerised machines.
Some major fields of health care in which computers are used are:
  • Diagnostic System - Computers are used to collect data and identify cause of illness.
  • Lab-diagnostic System - All tests can be done and reports are prepared by computer.
  • Patient Monitoring System - These are used to check patient's signs for abnormality such as in Cardiac Arrest, ECG etc.
  • Pharma Information System - Computer checks Drug-Labels, Expiry dates, harmful drug’s side effects etc.
  • Surgery : Nowadays, computers are also used in performing surgery.

Engineering Design

Computers are widely used in Engineering purpose.
One of major areas is CAD (Computer aided design). That provides creation and modification of images. Some fields are:
  • Structural Engineering - Requires stress and strain analysis for design of Ships, Buildings, Budgets, Airplanes etc.
  • Industrial Engineering - Computers deal with design, implementation and improvement of integrated systems of people, materials and equipments.
  • Architectural Engineering - Computers help in planning towns, designing buildings, determining a range of buildings on a site using both 2D and 3D drawings.

Military

Computers are largely used in defence. Modern tanks, missiles, weapons etc. Military also employs computerised control systems. Some military areas where a computer has been used are:
  • Missile Control
  • Military Communication
  • Military Operation and Planning
  • Smart Weapons




Communication

Communication means to convey a message, an idea, a picture or speech that is received and understood clearly and correctly by the person for whom it is meant for. Some main areas in this category are:
  • E-mail
  • Chatting
  • Usenet
  • FTP
  • Telnet
  • Video-conferencing

Government

Computers play an important role in government. Some major fields in this category are:
  • Budgets
  • Sales tax department
  • Income tax department
  • Male/Female ratio
  • Computerization of voters lists
  • Computerization of driving licensing system
  • Computerization of PAN card
  • Weather forecasting



iOS - First iPhone Application

Creating the First App

Now we are going to create a simple single view application (a blank app) that will run on the iOS simulator.
The steps are as follows.
Step 1 − Open Xcode and select Create a new Xcode project.


Step 2 − Select Single View Application.


Step 3 − Enter the product name, i.e., the name of the application, organization name, and then the company identifier.


Step 4 − Ensure that Use Automatic Reference Counting is selected in order to automatically release the resources allocated once it goes out of scope. Click Next.
Step 5 − Select the directory for the project and select create.


Step 6 − You will see a screen as follows −


In the screen above, you will be able to select the supported orientations, build and release settings. There is a field deployment target, the device version from which we want to support, lets select 4.3, which is the minimum deployment target allowed now. For now, these are not required and let's focus on running the application.
Step 7 − Now, select iPhone simulator in the drop down near Run button and select run.


Step 8 − That's it; you have successfully run your first application. You will get an output as follows −

Now let's change the background color, just to have a start with the interface builder. Select ViewController.xib. Select background option in the right side, change the color and run.


In the above project, by default, the deployment target would have been set to iOS 6.0 and auto-layout will be enabled. To ensure that our application runs on devices that are on iOS 4.3 onwards, we have already modified the deployment target at the start of creation of this application, but we didn't disable auto-layout.
To disable auto-layout, we need to deselect the auto-layout checkbox in the file inspector of each nib, i.e., the xib files. The various sections of Xcode project IDE are given in the following figure (Courtesy: Apple Xcode 4 User documentation).

File inspector is found in the inspector selector bar as shown above and auto layout can be unchecked there. Auto layout can be used when you want to target only iOS 6 devices. Also, you'll be able to use many new features like passbook if you raise the deployment target to iOS 6. For now, let's stick to iOS 4.3 as the deployment target.

Code of the First iOS Application

You will find five different files that would have been generated for your application. They are listed as follows −
  • AppDelegate.h
  • AppDelegate.m
  • ViewController.h
  • ViewController.m
  • ViewController.xib

AppDelegate.h

// Header File that provides all UI related items. 
#import

// Forward declaration (Used when class will be defined /imported in future)
@class ViewController;

// Interface for Appdelegate
@interface AppDelegate : UIResponder <UIApplicationDelegate>

// Property window
@property (strong, nonatomic) UIWindow *window;

// Property Viewcontroller

@property (strong, nonatomic) ViewController *viewController;
//this marks end of interface
@end
Important items in code −
  • AppDelegate inherits from UIResponder that handles iOS events.
  • Implements the delegate methods of UIApplicationDelegate, which provides key application events like finished launching, about to terminate and so on.
  • UIWindow object to manage and co-ordinate the various views on the iOS device screen. It's like the base view over which all other views are loaded. Generally there is only one window for an application.
  • UIViewController to handle the screen flow.

AppDelegate.m

// Imports the class Appdelegate's interface
import "AppDelegate.h"

// Imports the viewcontroller to be loaded
#import "ViewController.h"

// Class definition starts here
@implementation AppDelegate


// Method to intimate us that the application launched successfully
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions
:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Override point for customization after application launch.
self.viewController = [[ViewController alloc]
initWithNibName
:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
/* Use this method to release shared resources, save user data,
invalidate timers, and store enough application state information
to restore your application to its current state in case it is
terminated later. If your application supports background
execution, this method is called instead of
applicationWillTerminate: when the user quits.*/

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
/* Called as part of the transition from the background to the
inactive state. Here you can undo many of the changes made on
entering the background.*/

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
/* Restart any tasks that were paused (or not yet started) while
the application was inactive. If the application was previously in
the background, optionally refresh the user interface.*/

}

- (void)applicationWillTerminate:(UIApplication *)application
{
/* Called when the application is about to terminate. Save data if
appropriate. See also applicationDidEnterBackground:. */

}

- (void)applicationWillTerminate:(UIApplication *)application
{
/* Called when the application is about to terminate. Save data if appropriate.
See also applicationDidEnterBackground:. */

}

@end
Important items in code −
  • UIApplication delegates are defined here. All the methods defined above are UI application delegates and contains no user defined methods.
  • UIWindow object is allocated to hold the application allocated.
  • UIViewController is allocated as the window's initial view controller.
  • To make the window visible, makeKeyAndVisible method is called.

ViewController.h

#import  

// Interface for class ViewController
@interface ViewController : UIViewController

@end
Important items in code −
  • The ViewController class inherits the UIViewController, which provides the fundamental view management model for the iOS applications.

ViewController.m

#import "ViewController.h"

// Category, an extension of ViewController class
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
Important items in code −
  • Two methods implemented here are defined in the base class UIViewController.
  • Do initial setup in viewDidLoad which is called after the view loads.
  • didReceiveMemoryWarning method is called in case of memory warning.

Kategori

Kategori