How to identify whether application is running in background or not - blackberry

I have an application that ask's password while clicking the application icon(ie. while entering the application). Then i have set UiApplication.getUiApplication().requestBackground(); where application is running in background.
Now if am again enter into the application means it have ask password.
Help me pl.
With regards,
Sampath

You can use UiApplication.getUiApplication().isForeground() method to determine if your application is in the foreground.
The isForeground method is inherited from net.rim.device.api.system Application class which also supports requestForeground and requestBackground methods.
http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/ui/UiApplication.html

I think you may be interested in the Application.activate() method:
public void activate()
// Handles foregrounding event.
// The system invokes this method when it brings this application
// to the foreground. By default, this method does nothing.
// Override this method to perform additional processing
// when being brought to the foreground.
The UiApplication extends Application so this method is also available in your UiApplication subclass.

Related

Best practice for initial loading in iOS app

Just starting out iOS development.
When starting my app, I'd like it to check if the user has a known account and if they do, "login" by acquiring an access token and then display the main / first view. If they don't have an account or if login fails, they should be redirected to a login / registration screen.
Initially I thought I'd hide this process (check for account + call to get access token) behind a splash screen, but apparently this is against Apples guidelines. Is there a common / recommended way to do this on iOS?
By referencing to application:didFinishLaunchingWithOptions: you can read that this method is good for initializing.
Use this method (and the corresponding
application:willFinishLaunchingWithOptions: method) to complete your
app’s initialization and make any final tweaks. This method is called
after state restoration has occurred but before your app’s window and
other UI have been presented. At some point after this method returns,
the system calls another of your app delegate’s methods to move the
app to the active (foreground) state or the background state. This
method represents your last chance to process any keys in the
launchOptions dictionary. If you did not evaluate the keys in your
application:willFinishLaunchingWithOptions: method, you should look at
them in this method and provide an appropriate response. Objects that
are not the app delegate can access the same launchOptions dictionary
values by observing the notification named
UIApplicationDidFinishLaunchingNotification and accessing the
notification’s userInfo dictionary. That notification is sent
shortly after this method returns.
There may be several ways. But using singleton for token and launching your app is one of the best ways. As you might not need to use that launcher class again. Just for checking user have token and if yes then show main view otherwise login view.
Hope it helps you !!

Is there any callback methods to be called When the user closes the app from the Task Manager when app is going in the background state already?

Is there any callback methods to be called When the user closes the app from the Task Manager? Because i have to maintain the status i.e Online or Offline while killing the app from the task manger user should become offline.
No, there is no such method or function or method to handle this scenario.
func applicationWillTerminate(application: UIApplication){}
// This method will be called when system kills your app after suspending it for whatever reason.
There is no method to detect killing application by multitasking and swipe the app Up to kill(from task manager).
Though you can handle this scenario in
func applicationDidEnterBackground(application: UIApplication) {}
Previous answers contain needed information. The application has delegate #protocol methods that handle application appearance, focus, entereing background state or termination.
If your question is how to handle this events in the context of data transfer and sending some status outside - register NSNotification observer and postNotification from the delegate protocol handler. Notifications are being sent before any other actions and allow the app to inform remote resource that it will be closed or loses focus.
In Ruby
at_exit do
# Do whatever you want before exit
end
Or if you want to do something before a specific signal that causes your program to exit, then
trap :INT do
# Will be triggered when `SIGINT` is trapped
end
You can replace :INT with other signals you want to trap.

iOS Corespotlight search: When app is not running

When the app is running, the continueUserActivity method gets called in which I handle the deep linking into the right location. However, when the app is not running, this function never gets called. I believe in the case when the app is not running, the call goes into application:didFinishLaunchingWithOptions:.
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
{
if (userActivity.UserInfo.ContainsKey(CSSearchableItem.ActivityIdentifier))
{
// do stuff to handle deep link
}
}
The above implementation works fine when the app is backgrounded, but when I kill it the search results no longer deep link correctly.
Any clue on how to handle this in application:didFinishLaunchingWithOptions:? Is there a way to tell if the app is launched from a corespotlight search item specifically?
I just checked in my app by adding an alert to both methods.
When the app is running only the continuation method is called. When the app is not running both methods will be called.

which method calls on press of application icon on home screen when that application is running in background in blackberry?

does any one knows which method calls on pressing of application icon present on home screen when that application is running in background in blackberry?
I want to write code for page refreshment their? Does any one have idea please tell me?
Most likely UiApplication.activate() is what are looking for. The API says:
The system invokes this method when it brings this application to the foreground. By default, this method does nothing. Override this method to perform additional processing when being brought to the foreground.
If you are using Alternate entry point then
check that in your main method like this
public static void main(String[] args) {
if(args.length>0&&"alternate".equals(args[0])){
//call Background process here
}
else{
// call your gui application here
}
}

UiApplication.activate() method called post app install on some BlackBerry Bolds. Why?

I'm having troubles with the UiApplication.activate() method firing post-app-installation (OTA install).
I have:
public class PlayerApp extends UiApplication
public PlayerApp() {
new Thread(this).start();
}
public void run() { ... }
public void activate() { ... }
I'm having troubles with the activate() method. It's firing to early, it's firing post--installation when it shouldn't (I thought it should fire when the application is selected by the user from the menu). What makes it worse it's not occuring on all Bolds. The BB is meant to ask for a reboot, but activate() is firing before this point and plays hell with the UI.
Questions. When does activate() really fire? Should activate() be firing post-install anyway? Is there a way to handle activate() firing post-installation? Is this a bug in the rim apis?
Note: The problem appears on BB Bold 4.6.0.144/4.0.0.143 and thus far I've not been able to replicate the issue on 4.6.0.282/4.0.0.235.
Edit: Installation flow: OTA link > Download > Install > 'Yes' to 'Trust application status' > AutoStart app > Trouble starts here.
According to the API docs activate():
The system invokes this method when it brings this application to the foreground. By default, this method does nothing. Override this method to perform additional processing when being brought to the foreground.
So, I suspect after OTA install the user is given the option of running the app which, when accepted, brings the app to the foreground. It is difficult to be certain without seeing your startup code. If your app is configured to autostart, then it will be "autostarted" after install. If this casues the UI to be instantiated and brought to the foreground, the activate will be called at that time.

Resources