Вы находитесь на странице: 1из 49

bada Tutorial: Application

bada 1.2.0 Copyright Copyright 2010 Samsung Co., Ltd. All Co., Ltd. All rights reserved. 2010 Samsung Electronics Electronics rights reserved. 1

Contents (1/2)
Essential Classes Relationships between Classes Overview bada Applications
Application Model Launching Application Terminating Application

Application State Transition


Application Life-cycle Foreground and Background

System Events Application Framework Internationalization Launching Applications


Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved. 2

Contents (2/2)
Notifications AppControl
Application Control ID Operation ID Getting an AppControl AppControl Examples Create an Application Save and Restore Application Settings Handle Screen Events Use Sign-In Application Control Launch Other Applications and Handle Launch Arguments Example: Launching Applications Conditionally Example: Creating a Notification View New Application Details through Samsung Apps before Installation

Examples:

FAQ
Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved. 3

Essential Classes
Major classes
Feature Provided by Application AppResource AppRegistry NotificationManager AppControl AppManager

Provides the base class to create applications. It initializes and terminates the application, and also provides handlers for system events.
Provides localized application string resources. Provides a repository to save and load user applications state and context. Sends notifications to the user. Provides application launching mechanism to use other application control features. Finds the specific application control.

Interfaces
Feature Provided by IAppFrame IAppControlEventListener

Provides an interface to the application frame. Provides a listener for AppControl.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

Relationships between Classes


<<interface>> IAppControlEventListener AppManager Application <<interface>> IAppFrame

OnAppControlCompleted()

FindAppControl()

AppControl

AppRegistry

Start() MyApplication

AppResource

Note: This is an external class created by the developer. It does not belong to the App namespace. NotificationManager

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

Overview
The App namespace contains classes and interfaces that provide the foundations for developing bada applications. Key features include:
Application framework. Background and foreground event handling. Application Control.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

bada Applications
The application framework provides:
Application life-cycle management:
Initialization and termination Background and foreground handling

Event handling:
Battery and memory events

Your Application
Application Framework

Application control:
Dial, contact, browser, media, and messaging
Operating System

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

Application Model (1/2)


In the bada platform, there are two application types:
Base applications:
Stored in the ROM and not removable via the Application manager. For example, Dialer, Contact, Camera, and Music player.

bada applications:
Installable and removable applications. In this document, the word application refers to a bada application.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

Application Model (2/2)


A bada application running in the foreground is sent to the background when base applications are launched, for example when receiving an incoming voice call or user switching to home screen. An application can utilize various device platform features provided by application controls through the AppControl class. bada platform task management
Only one bada application can run at a time.
If a bada application is already running when launching another bada application, the first is always terminated by the platform.

Multi-tasking is available between a bada application and base applications. That is, one bada application can run simultaneously with multiple base applications.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

Launching Application
An application is launched when the user clicks the icon in the main menu. The system loads the necessary libraries and application executable binary to the memory. The applications entry point (OspMain()) creates an instance of the application and executes it. In the application initialization phase (OnAppInitializing()), resources, UI components, and previous application states can be loaded or initialized.

Main menu

Application

int OspMain()

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

10

Terminating Application (1/2)


The application closes for one of 2 reasons:
1. When the bada application itself calls the Application::Terminate() method, the application is terminated. 2. When the application is in the foreground, the user pressing the End key terminates the application.

The system forces the application to shut down:


1. If a second application launches while the first is running, the first application is terminated. All bada applications follow a single bada application policy, so only one bada application can run at a time. 2. When memory or battery power is extremely low, the system terminates the application.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

11

Terminating Application (2/2)


Application termination tasks must be handled in the OnAppTerminating() method, which is called when the application terminates. When terminating:
The application must close quickly. The application must free the resources it has been using to avoid memory leakage.
The allocated UI control objects, such as the Frame, Form, and their child controls, are released before the OnAppTerminating() method is called. They are not accessible from within the OnAppTerminating() method.

The application must close all pending connections to servers. The application can save its own state or context through AppRegistry. For instance, when the application is launched, it can resume from the last form from the previous execution. The forcedTermination argument specifies that the application is being terminated by the system. It is:
True, when the application is forced to terminate, for example due to second bada application launching, low battery, or other system interruptions. False, when the termination is initiated by the user pressing the End key or closing the application from the task manager, or by the application calling Terminate() itself.
Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved. 12

Application State Transition (1/2)


Applications have the following states with corresponding event handlers:
Initializing
Application framework initializes the application and creates the applications frame. If the OnAppInitializing() method returns false, application state changes to Terminating and it exits. If the OnAppInitializing() returns true, the application framework proceeds to Running state.

Running Terminating
The application exits the event loop and frees its own resources.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

13

Application State Transition (2/2)


Terminated
It releases the control of the flow to the system.

- Process events. Initialization succeeds Create Initializing Initialization fails Terminating Running Termination

- Exit event loop. - Call the applications OnAppTerminating() method. - Destroy allocated resources.

- Register application context in the system. - Create the application frame . - Call the applications OnAppInitializing() method.

- Application destroyed.

Terminated

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

14

Application Life-cycle
The diagram illustrates where the application state events occur in terms of the application life-cycle.
Application Launch
Showing splash image Hiding splash image

OnAppInitializing() Application comes to the foreground OnForeground()

Running

OnBackground()
Another window comes to the foreground (for example, a system popup or another application)

Termination

OnAppTerminating()

Application Exit

Application life-cycle Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved. 15

Foreground and Background (1/3)


Foreground:
Applications are visible when they are in the foreground. When an application is first launched, the OnForeground()method is called. An application is brought to the foreground from the background when:
The running application is selected from the task manager. The application icon is selected in the main menu.

When the application is brought to the foreground:


Resume graphics processing (3D or animation) since the application now has focus. Resume the operations which were stopped when the application was last moved to the background.

When the system needs to refresh a screen component, it can call the OnForeground()method even if the application is present in the foreground.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

16

Foreground and Background (2/3)


Background:
Applications are not visible when they are in the background. An application moves to the background when :
The Home key is pressed. Other windows pop up, such as windows for incoming calls and alarms.

When the application is sent to the background:


Stop graphics processing (3D, animation, etc.) since they will not be displayed anyway. Release unnecessary resources. Stop media processing, haptic and sensors manipulations.
- Home key pressed - Other windows pop up

- OnForeground() is called Foreground Background

- OnBackground() is called

-Selected from the task manager - Icon pressed in the main menu

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

17

Foreground and Background (3/3)


The following diagram illustrates the various events and states from the application and the application frameworks perspective.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

18

System Events (1/3)


System events must be properly handled by the Application class event handlers:
Battery event: Applications that use multimedia resources, such as the camera and media player, need to check the battery level in the OnBatteryLevelChanged() event handler:
If the level is EMPTY, terminate the application. If the level is CRITICAL, stop using multimedia features, since they are not guaranteed to function properly at this battery level.

Memory event: When memory is low, the OnLowMemory() event handler is called. Free unused memory from the heap in this event handler.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

19

System Events (2/3)


Screen event:
Applications can receive screen events in OnScreenOn() and OnScreenOff() event handlers if they register a screen event listener. When the OnScreenOff() event handler is triggered, the application must reduce power consumption by releasing the activated resources, such as 3D, multimedia, and sensors, which are no longer used. The released resources can be acquired again when the OnScreenOn() event handler is triggered. The resources must be handled efficiently by the OnForeground()/ OnBackground() and OnScreenOn()/OnScreenOff() event handlers. Be careful not to duplicate or delete resources. When the device is in auto lock mode, OnBackground()is called directly after OnScreenOff().
The following events are triggered when the backlight time expires:
OnScreenOff() If device is in auto lock mode, OnBackground() is called after OnScreenOff() when the lock UI is displayed.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

20

System Events (3/3)


The following events are triggered when the unlock key is pressed.
If the touch lock is enabled, OnScreenOn() is triggered. OnForeground() is called after the lock UI disappears.

When the lock key is pressed explicitly, only OnBackground() is called after the lock UI is displayed. When the backlight turns off, OnScreenOff() is called.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

21

Application Framework

Application AppManager

Application:
All applications must derive from Application class
IAppFrame AppResource

AppManager:
Application manager class Finds an AppControl instance

AppControl

AppRegistry

NotificationManager

IAppFrame:
UI frame interface Frame is the main window in an application

AppResource:
Application resource class Can contain localized strings

AppControl:
Application control class Used to start an application and control specific behavior

NotificationManager:
Notification manager class Used to alert the user about notifications
Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved. 22

Internationalization (1/2)
String resource is supported for multiple languages. Each localized string is saved to each xml file in Res folder.
For example: eng-GB.xml, fra-FR.xml, ita-IT.xml, deu-DE.xml, kor-KR.xml

[IDE String Resource]

AppResource handles localized string resource based on preferred display language that is defined in the device settings.
Your App Form

AppResource

Hello
eng-GB.xml
Menu Back

Language Setting

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

23

Internationalization (2/2)
Retrieving localized strings
1. Prepare the localized strings table with the UI Builder. For more information, see Using String Tables in the Development Environment tutorial. 2. Get the localized string from the AppResource class. AppResource retrieves the chosen language from the display language settings and returns the localized strings. AppResource::GetString(const String& id, String& loadedString)
Application* pApp = Application::GetInstance(); String str1; r = pApp->GetAppResource()->GetString("IDS_STRING1", str1);

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

24

Launching Applications (1/2)


Launching other applications:
A bada application can launch other applications using the AppManager::LaunchApplication()method. The AppManager::LaunchApplication() method requires the SYSTEM privilege level, and to use the method, you must assign the APP_SERVICE privilege group to your application. All bada applications follow the single application policy. Therefore, the OnAppTerminating() method is called immediately after the LaunchApplication() method, and the calling application is terminated. You can retrieve the launch arguments from an application by using the Application::OnUserEventReceivedN() method. For more information, see the API Reference.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

25

Launching Applications (2/2)


Launching applications with conditions:
A bada application can launch itself with a specified condition using the AppManager::RegisterAppLaunch() method with the SYSTEM privilege level and APP_SERVICE privilege group. The application is newly launched when the condition is fulfilled, unless the application is already running. If the application is running, a notification is delivered in the Application::OnUserEventReceivedN() event hander. A launch condition can be specified as follows:
Type
Due time

Condition format
LDataTime=mm/dd/yyyy hh:mm:ss

Description
Launch at the local time mm/dd/yyyy hh:mm:ss . The time format matches the output format of Base::DateTime::ToString().
Launch on the serial communication input command.

Serial

LSerial=command

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

26

Notifications
An application can notify the user using the NotificationManager::Notify() method. The NotificationManager::Notify() method requires the NOTIFICATION privilege group. In addition, you must define an icon for the ticker or quick panel in the application properties. A notification can be a combination of the following types:
Ticker Quick panel Badge number Sound

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

27

AppControl (1/2)
AppControl is a standard mechanism for using specific operations exported by base applications AppControl can communicate data and get back results. AppControl instance can be created from the AppManager. AppManager finds the service providing application control and returns it for your application to use. AppControls can be identified using 2 parameters:
Application Control ID:
Defines the variable for identifying each application control instance. For example, APPCONTROL_DIAL.

Operation ID:
Defines the variable for identifying the behavior of each application control instance. For example, OPERATION_VIEW.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

28

AppControl (2/2)
The result of the application controls execution is returned by IAppControlEventListeners OnAppControlCompleted() method.
OnAppControlCompleted() is invoked when an application finishes its operation and a control callback event occurs.

Some AppControls require privileges to use them:


For example, Call and Browser requires Normal privilege.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

29

Application Control ID (1/3)


AppControl name
APPCONTROL_CONTACT

Operation ID
OPERATION_PICK OPERATION_ADD

Description
This operation can be used to read the phone number, email address, contact ID, or vCard file path for one or more contacts in the contact database. This operation can be used to add a contact to the contact database. The parameters passed to this AppControl are automatically filled in the appropriate fields in the Add Contact UI. This operation can be used to edit a contact in the contact database. The parameters passed to this AppControl are automatically filled in the appropriate fields in the Edit Contact UI. This operation can be used to view a vCard file. The contact details are displayed only if the vCard file path is specified. This operation can be used with either the single or the multiple selection feature to select one or more Calendar application items, such as events, to-do items, or memos. Event and to-do items are returned as .vcs files and memo items as .vnt files. This operation can be used to view a vCalendar file or a calendar event. The event details are displayed only if the vCalendar (event) file path or the record ID of the event (used in Social::Calendarbook) is specified. The to-do item details are displayed only if the vCalendar (to-do) file path is specified. This application control can be used to launch the Dial UI. The parameter passed to this application control is displayed on the screen. Users can edit this number and make calls using the Call key. This operation can be used to call the specified number. Using this AppControl requires special privileges. This operation can be used to open a Web browser using the specified URL. Using this AppControl requires special privileges.
Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved. 30

OPERATION_EDIT

OPERATION_VIEW APPCONTROL_CALENDAR OPERATION_PICK

OPERATION_VIEW

APPCONTROL_DIAL

OPERATION_DEFAULT

APPCONTROL_CALL APPCONTROL_BROWSER

OPERATION_DEFAULT OPERATION_DEFAULT

Application Control ID (2/3)


AppControl name
APPCONTROL_SIGNIN

Operation ID
OPERATION_SIGNIN

Description
This operation can be used to sign in to the bada Server. After the user has signed in for the first time, this operation handles all subsequent sign-ins automatically. Using this AppControl requires special privileges. This operation can be used to sign out from the bada Server. This operation signs out without displaying any dialog. Using this AppControl requires special privileges. This operation can be used to launch the Camera UI to capture images or record video. This operation can be used to compose SMS or MMS messages. The parameters passed to this application control are automatically filled in the appropriate fields in the displayed message composer. This operation can be used to compose email messages. The parameters passed to this application control are automatically filled in the appropriate fields in the displayed message composer. This operation can be used to obtain the details of a Bluetooth profile on the device.

OPERATION_SIGNOUT

APPCONTROL_CAMERA APPCONTROL_MESSAGE

OPERATION_CAPTURE OPERATION_EDIT

APPCONTROL_EMAIL

OPERATION_EDIT

APPCOTNROL_BT

OPERATION_PICK

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

31

Application Control ID (3/3)


AppControl name
APPCONTROL_MEDIA

Operation ID
OPERATION_PICK

Description
This operation can be used to select one or more media files , such as images or video recordings, from the My Files folder. This operation can be used to view image files on the device. This operation can be used to play video files on the device. This operation can be used to play audio files on the device. This operation can be used to view the settings of a specific feature category. Currently, only the location category is supported.

APPCONTROL_IMAGE APPCONTROL_VIDEO APPCONTROL_AUDIO APPCONTROL_SETTINGS

OPERATION_VIEW OPERATION_PLAY OPERATION_PLAY OPERATION_DEFAULT

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

32

Operation ID
Operations specify the specific behavior or action that must be performed.
Operation ID OPERATION_ADD OPERATION_CAPTURE OPERATION_EDIT OPERATION_DEFAULT OPERATION_PICK OPERATION_PLAY OPERATION_VIEW Description Adds an item or content to a specific AppControl. Captures an item or content in a specific AppControl. Edits an item or content in a specific AppControl. Launches the AppControl without any operation. Obtains data from a specific AppControl. Plays an item or content in a specific AppControl. Displays an item or content in a specific AppControl.

OPERATION_SIGNIN
OPERATION_SIGNOUT

Displays a sign-in window.


Signs out of a session.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

33

Getting an AppControl
IAppControlEventListener OnAppControlCompleted()

5. Asynchronously send result to AppControl event listener.

bada Application AppControl

Base Application (For example, Contact)


AppControl

1. Find AppControl. 3. Start AppControl.

AppManager [AppControl Resolver]

4. Launch the application AppControl ID and operation ID.

2 Resolve the AppControl ID and operation ID.

AppControls Registry

#Dial #Video type= #SignIn type= Path= #Browser type= Path= type= type= Path= Path= Path=

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

34

AppControl Examples
APPCONTROL_MEDIA:
Launches the media application to select audio, video, or image content from the Media folder. Receives selections in an event handler.
AppControl ID: APPCONTROL_MEDIA Operation ID: OPERATION_PICK Option: type:video selectionType:single
Caller Application Media Application

APPCONTROL_DIAL:
Launches the dialer application with a pre-filled phone number. Requires normal privilege.

AppControl ID: APPCONTROL_DIAL Operation ID: NONE Option: tel:+82312798707


Caller Application Dialer Application

The calling application receives information of the selected media, i.e. URI.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

35

Example: Create an Application (1/2)


This example illustrates how application default methods are created.
Open \<BADA_SDK_HOME>\Examples\UIApplication\src \HelloWorld.cpp. 1. Create the HelloWorld application code using the Form Based Application template.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

36

Example: Create an Application (2/2)


Notes
Applications must derive from the Application class. You must create and download your applications manifest.xml file from bada Developers. In addition to the information above (name, ID, secret code), it contains other information necessary for your application, such as privileges and device profiles.
Application Name GetAppName()

Application

Application ID GetAppId()
Secret Code GetAppSecret()

Manifest.xml

MyApplication

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

37

Example: Save and Restore Application Settings (1/2)


Save and restore application state.
1. In the OnAppInitializing() method, use AppRegistry to retrieve application settings: AppRegistry::Get(key, value)

2. The first time an application runs, the registry entry must be added: AppRegistry::Add(key, value)
3. Save application settings to disk in the registry: AppRegistry::Save() 4. Set registry values in the OnAppTerminating() event handler: AppRegistry::Set(key, value)

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

38

Example: Save and Restore Application Settings (2/2)


bool MyApplication::OnAppInitializing(AppRegistry& appRegistry) { String message("NONE"); r = appRegistry.Get("LastMessage", message); if(r == E_KEY_NOT_FOUND { appRegistry.Add("LastMessage", message); } // Enumeration definitions are defined elsewhere. // enum { INIT=0, PLAYING, SCORE } GameStatus = INIT; int gamestatus = GameStatus; r = appRegistry.Get("GameStatus", gamestatus); if(r == E_KEY_NOT_FOUND { appRegistry.Add("GameStatus", gamestatus); } appRegistry.Save(); } bool MyApplication::OnAppTerminating(AppRegistry& appRegistry) { result r = E_SUCCESS; r = appRegistry.Set("LastMessage", "Who destroyed"); //enum { INIT=0, PLAYING, SCORE } GameStatus = PLAYING; appRegistry.Set("GameStatus", (int)GameStatus); appRegistry.Save(); }

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

39

Example: Handle Screen Events


This example illustrates how to handle a sound resource during screen on and screen off events. You can handle other resources in the same way.
1. Implement the ScreenEventListener to handle screen events. 2. Check the sound status using the boolean value of the IsPlaying variable. 3. Play or stop the sound using PlaySound()or StopSound() accordingly.
bool MyApplication::OnAppInitializing(AppRegistry& appRegistry) { PowerManager::SetScreenEventListener(*this); } void MyApplication::OnScreenOn (void) { // Check if sound is off, then turn on sound. if(!IsPlaying) PlaySound(); } void MyApplication::OnScreenOff (void) { if(IsPlaying) StopSound(); } void MyApplication::OnForeground() { if(!IsPlaying) PlaySound(); } void MyApplicaiton::OnBackground() { if(IsPlaying) StopSound(); }

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

40

Example: Use Sign-In Application Control


1. Get an AppControl instance by calling the FindAppControlN() method. Provide the SignIn Control ID as parameter: AppManager::FindAppControlN(APPCONTROL_SIGNIN, OPERATION_SIGNIN) 2. If the FindAppControlN() method returns an AppControl instance, start the AppControl by calling its Start() method: AppControl::Start(null, this)

Notes:
If you require event handlers, implement an IAppControlEventListener.
AppControl* pAc = AppManager::FindAppControlN(APPCONTROL_SIGNIN, OPERATION_SIGNIN); if(pAc != null) { pAc->Start(null, this); delete pAc; } else AppLog("AppControl Not Found. \n");

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

41

Example: Launch Other Applications and Handle Launch Arguments (1/2)


This example illustrates how to launch other applications from a bada application and retrieve the launch arguments. 1. A caller application launches another application with arguments using the LaunchApplication() method. 2. The OnAppTerminating()method is called, terminating the caller application. 3. The called application is launched. If the launch arguments exist, requestId is assigned as a reserved launch ID (AppLaunchRequestId).

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

42

Example: Launch Other Applications and Handle Launch Arguments (2/2)


Caller application:
AppId calleeAppId = L1234567890; AppManager *pAppManager = AppManager::GetInstance(); ArrayList *pArgList = new ArrayList(); pArgList->Construct(); String *aArg = new String(Lyourdata); pArgList->Add(*aArg); r = pAppManager->LaunchApplication(calleeAppId, pArgList, AppManager::LAUNCH_OPTION_DEFAULT);

Called application:
void CalleeApp::OnUserEventReceivedN (RequestId requestId, Osp::Base::Collection::IList *pArgs) { if(requestId == AppLaunchRequestId) // If launch arguments exist { if(pArgs) { for(int i = 0; i < pArgs->GetCount(); i++) AppLog("pData[%d]=%S", i, ((String*)(pArgs->GetAt(i)))->GetPointer()); // pArgs[0] represents the launch type (for example, APP_LAUNCH_NORMAL value) // pArgs[1] represents the operation of the launch (default value is OPERATION_DEFAULT). // pAgrs[>=2] contains the actual arguments sent from the caller (for example, yourdata) } else // Handling User Events

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

43

Example: Launching Applications Conditionally


This example illustrates how to launch an application conditionally at a given time. The same launch argument scheme can be exploited as the LaunchApplication() method.
1. Define the condition in the proper String format. 2. Register the application for the launch with arguments using the RegisterAppLaunch() method. 3. The registered application is launched at the defined time.

DateTime time; SystemTime::GetCurrentTime(WALL_TIME, time); Time.AddMinutes(1); String condition; condition.Format(40, LDateTime=%S, time.ToString().GetPointer()); ArrayList* pArgList = newArrayList(); pArrayList->Construct(); String *aArg = new String(Lyourdata); pArgList->Add(*aArg); r = AppManager::GetInstance()>RegisterAppLaunch(condition, pArgList, AppManager::LAUNCH_OPTION_DEFAULT);

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

44

Example: Creating a Notification


This example illustrates how to inform the user with a ticker and notification.
1. Construct an instance of the NotificationManager class. 2. If you want to send a badge notification, handle the badge number properly. 3. Send the notification.
NotificationManager* pNotiMgr = new NotificationManager(); pNotiMgr->Construct(); Int badgeNumber = pNotiMgr->GetBadgeNumber(); badgeNumber++; r = pNotiMgr->Notify(LA new message has arrived., badgeNumber);

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

45

Example: View New Application Details through Samsung Apps before Installation (1/2)
This example illustrates how you can launch the SamsungApps application to view the details of a new application on offer at Samsung Apps before deciding to download and install the new application. The SamsungApps application provides users easy access to new applications. 1. A caller application retrieves the SamsungApps application ID using the SystemInfo::GetValue()method. 2. The caller application launches the SamsungApps application with the LaunchApplication() method, using the application ID of the new application you want to view as a parameter. 3. The OnAppTerminating()method is called, terminating the caller application. 4. The SamsungApps application is launched and displays the details of the new application.
Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved. 46

Example: View New Application Details through Samsung Apps before Installation (2/2)
Caller application:
AppId samsungAppsAppId; Osp::System::SystemInfo::GetValue("SamsungAppsAppId", samsungAppsAppId); AppManager *pAppManager = AppManager::GetInstance(); ArrayList *pArgList = new ArrayList(); pArgList->Construct(); String *aArg = new String(L1234567890); // ID of the new application whose details you want to view pArgList->Add(*aArg); r = pAppManager->LaunchApplication(samsungAppsAppId, pArgList, AppManager::LAUNCH_OPTION_DEFAULT);

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

47

FAQ
Where do I initialize and free-up application resources?
Initialize them in the OnAppInitializing() method. Free non UI resources in the OnAppTerminating() method, but UI resources(e.g. form and its child controls) is freed automatically when the application closed. You do not need to free them explicitly. Please review the UI parts of this document about UI resource.

Do I have to set my applications ID somewhere?


No, an application ID (a unique identifier bound to a bada application) is created from the bada developer site and saved into the application manifest file (manifest.xml). The bada IDE does not automatically generate the GetAppId(), GetAppName(), and GetAppSecret() methods, since they are member methods of the Application class.

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

48

Copyright 2010 Samsung Electronics Co., Ltd. All rights reserved.

49