You are on page 1of 49

bada Tutorial:

Application

bada 1.2.0
Copyright © Copyright
2010 Samsung Electronics
© 2010 Samsung Co., Ltd. All Co.,
Electronics rightsLtd.
reserved. 1
All rights reserved.
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
• 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
• FAQ

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


Essential Classes
• Major classes
Feature Provided by
Provides the base class to create applications. It initializes and terminates the application,
Application
and also provides handlers for system events.
Provides localized application string resources. AppResource

Provides a repository to save and load user application‟s state and context. AppRegistry

Sends notifications to the user. NotificationManager

Provides application launching mechanism to use other application control features. AppControl

Finds the specific application control. AppManager

• Interfaces
Feature Provided by

Provides an interface to the application frame. IAppFrame

Provides a listener for AppControl. IAppControlEventListener

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


Relationships between Classes
<<interface>>
<<interface>> AppManager Application IAppFrame
IAppControlEventListener

OnAppControlCompleted() FindAppControl()

AppRegistry
AppControl

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. 5


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. 6


bada Applications
The application framework provides:
– Application life-cycle management:
• Initialization and termination
• Background and foreground handling
Your Application
– Event handling:
Application Framework
• Battery and memory events
– Application control:
• Dial, contact, browser, media,
and messaging
Operating System

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


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. 8


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. 9


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 application‟s 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 application‟s
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.

- Exit event loop.


- Process events.
- Call the application‟s
OnAppTerminating()
Initialization
succeeds Running Termination method.
- Destroy allocated resources.
Create
Initializing Terminating
Initialization fails

- Register application context in the


system.
- Create the application frame . - Application destroyed. Terminated
- Call the application‟s
OnAppInitializing() method.

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


Application Life-cycle
Application
The diagram illustrates where Launch

the application state events Showing splash image


Hiding splash image
occur in terms of the application OnAppInitializing()
life-cycle.
Application comes to
the foreground
OnForeground()

Running OnBackground()

Termination Another window


comes to the
foreground
(for example, a
OnAppTerminating() system popup or
another application)

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 - OnBackground() is called


Foreground Background

-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 framework‟s 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 IAppFrame AppResource
Application class
• AppManager: AppControl AppRegistry
– Application manager class
– Finds an AppControl instance 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 Condition format Description
Due time L”DataTime=„mm/dd/yyyy hh:mm:ss‟” Launch at the local time
„mm/dd/yyyy hh:mm:ss‟ .
The time format matches the output
format of
Base::DateTime::ToString().
Serial L”Serial=„command‟” Launch on the serial communication
input „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 control‟s execution is returned by
IAppControlEventListener‟s 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 Operation ID Description
APPCONTROL_CONTACT OPERATION_PICK 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.
OPERATION_ADD 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.
OPERATION_EDIT 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.
OPERATION_VIEW
The contact details are displayed only if the vCard file path is specified.
APPCONTROL_CALENDAR OPERATION_PICK 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
OPERATION_VIEW
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.
APPCONTROL_DIAL OPERATION_DEFAULT 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.
APPCONTROL_CALL OPERATION_DEFAULT This operation can be used to call the specified number. Using this AppControl
requires special privileges.
APPCONTROL_BROWSER OPERATION_DEFAULT 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


Application Control ID (2/3)

AppControl name Operation ID Description


APPCONTROL_SIGNIN OPERATION_SIGNIN 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.

OPERATION_SIGNOUT 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.

APPCONTROL_CAMERA OPERATION_CAPTURE This operation can be used to launch the Camera UI to capture images or
record video.
APPCONTROL_MESSAGE OPERATION_EDIT 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.
APPCONTROL_EMAIL OPERATION_EDIT 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.
APPCOTNROL_BT OPERATION_PICK This operation can be used to obtain the details of a Bluetooth profile on the
device.

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


Application Control ID (3/3)

AppControl name Operation ID Description


APPCONTROL_MEDIA OPERATION_PICK This operation can be used to select one or more media files , such as images
or video recordings, from the My Files folder.

APPCONTROL_IMAGE OPERATION_VIEW This operation can be used to view image files on the device.

APPCONTROL_VIDEO OPERATION_PLAY This operation can be used to play video files on the device.

APPCONTROL_AUDIO OPERATION_PLAY This operation can be used to play audio files on the device.

APPCONTROL_SETTINGS OPERATION_DEFAULT This operation can be used to view the settings of a specific feature category.
Currently, only the location category is supported.

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 Description
OPERATION_ADD Adds an item or content to a specific AppControl.

OPERATION_CAPTURE Captures an item or content in a specific AppControl.

OPERATION_EDIT Edits an item or content in a specific AppControl.

OPERATION_DEFAULT Launches the AppControl without any operation.

OPERATION_PICK Obtains data from a specific AppControl.

OPERATION_PLAY Plays an item or content in a specific AppControl.

OPERATION_VIEW Displays an item or content in a specific AppControl.

OPERATION_SIGNIN Displays a sign-in window.

OPERATION_SIGNOUT Signs out of a session.

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


Getting an AppControl
IAppControlEventListener 5. Asynchronously send result to
OnAppControlCompleted() AppControl event listener.

bada Base Application


Application (For example, Contact)
AppControl AppControl

1. Find AppControl. 4. Launch the application AppControl


3. Start AppControl. ID and operation ID.
AppManager

[AppControl Resolver]

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: • APPCONTROL_DIAL:
– Launches the media – Launches the dialer
application to select audio, application with a pre-filled
video, or image content from phone number.
the Media folder.
– Requires normal privilege.
– Receives selections in an
event handler.

AppControl ID: APPCONTROL_MEDIA


Operation ID: OPERATION_PICK
Option: “type:video” AppControl ID: APPCONTROL_DIAL
“selectionType:single” Operation ID: NONE
Option: “tel:+82312798707”

Caller Media
Application Application Caller Dialer
Application 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 application‟s 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
Application GetAppName()

Application ID Manifest.xml
GetAppId()

MyApplication Secret Code


GetAppSecret()

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& bool MyApplication::OnAppTerminating(AppRegistry&


appRegistry) appRegistry)
{ {
… …
String message("NONE"); result r = E_SUCCESS;
r = appRegistry.Get("LastMessage", message); r = appRegistry.Set("LastMessage", "Who destroyed");
//enum { INIT=0, PLAYING, SCORE } GameStatus =
if(r == E_KEY_NOT_FOUND PLAYING;
{ appRegistry.Set("GameStatus", (int)GameStatus);
appRegistry.Add("LastMessage", message); appRegistry.Save();
} …
// 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();

}

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


Example: Handle Screen Events
This example illustrates how to bool MyApplication::OnAppInitializing(AppRegistry&
appRegistry)
handle a sound resource during {

screen on and screen off events. PowerManager::SetScreenEventListener(*this);

You can handle other resources }

in the same way. void MyApplication::OnScreenOn (void)


{
// Check if sound is off, then turn on sound.
if(!IsPlaying)
PlaySound();
1. Implement the }
ScreenEventListener to void MyApplication::OnScreenOff (void)
handle screen events. {
if(IsPlaying)
2. Check the sound status StopSound();
}
using the boolean value of
void MyApplication::OnForeground()
the IsPlaying variable. {
if(!IsPlaying)
3. Play or stop the sound using PlaySound();
}
PlaySound()or
StopSound() accordingly. 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 = L”1234567890”;

AppManager *pAppManager = AppManager::GetInstance();

ArrayList *pArgList = new ArrayList();


pArgList->Construct();

String *aArg = new String(L”yourdata”);


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
DateTime time;
conditionally at a given time. The SystemTime::GetCurrentTime(WALL_TIME, time);
same launch argument scheme Time.AddMinutes(1);

can be exploited as the String condition;


condition.Format(40, L”DateTime=„%S‟”,
LaunchApplication() time.ToString().GetPointer());
method. ArrayList* pArgList = newArrayList();
1. Define the condition in the
proper String format. pArrayList->Construct();

2. Register the application for String *aArg = new String(L”yourdata”);


pArgList->Add(*aArg);
the launch with arguments
using the r = AppManager::GetInstance()-
>RegisterAppLaunch(condition, pArgList,
RegisterAppLaunch() AppManager::LAUNCH_OPTION_DEFAULT);
method.
3. The registered application is
launched at the defined time.

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(L”A 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(L”1234567890”); // 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 application‟s 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

You might also like