Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer
Accepted Solution

Showing my own app when i unlock the screen

I have an requirement like,when i unlock the screen instead of showing home screen,i want to directly invoke a third party app,and if i exit that app,i can show my home screen than.Is it fesible?

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

yes that is possible make your home screen of app as global screen, there is an event to check device is lock or not, u will show your screen in that event
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

Any sample code will be helpful

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

You are creating your own lock screen or you are using system device lock
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
	 public MyScreen() {
	        synchronized (UiApplication.getEventLock()) {
	            UiEngine ui = Ui.getUiEngine();

	            String title = "Dialog Title";
	            String text = "This is a code to show globalscreen "
	                    + "Its very helpful in understanding " 
	                    + "With the help of it,we can "
	                    + "achieve alot of things.";
	            GlobalDialog screen = new GlobalDialog(title, text);

	            ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
	        }
	    }
	 
	 
}
class GlobalDialog extends PopupScreen implements FieldChangeListener {
    ButtonField mOKButton = new ButtonField("OK", ButtonField.CONSUME_CLICK
            | FIELD_HCENTER);

    public GlobalDialog(String title, String text) {
        super(new VerticalFieldManager());
        add(new LabelField(title));
        add(new SeparatorField(SeparatorField.LINE_HORIZONTAL));
        add(new LabelField(text, DrawStyle.HCENTER));
        mOKButton.setChangeListener(this);
        add(mOKButton);
    }

    public void fieldChanged(Field field, int context) {
        if (mOKButton == field)
            close();
    }
}

 This is my simple mainscreen.I have made this project as AutoStartUp.So when i restart my device it gets executed first.Thats fine.But suppose i lock my screen and unlock,than the appp doesnt get executed again

 

public class MyApp extends UiApplication
{
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args)
    {
    	
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }
    

    /**
     * Creates a new MyApp object
     */
    public MyApp()
    {        
        // Push a screen onto the UI stack for rendering.
    	
    	 if(ApplicationManager.getApplicationManager().isSystemLocked()){
    		UiApplication.getUiApplication().invokeLater(new Runnable() {
				
				public void run() {
					Dialog.alert("LOCK");
					
				}
			}) ;
    	 }
    	 else {
        pushScreen(new MyScreen());
    	 }
    }    
}

 This is my main UI class

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

public class MyApp extends UiApplication implements SystemListener
{
    public static void main(String[] args)
    {
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }
    public MyApp()
    {     
    	if (ApplicationManager.getApplicationManager().inStartup())
        {
    		addSystemListener(this);
        }
		else
		{
			doStartupWorkLater();	
		}
    }
	private void doStartupWorkLater() 
	{
		 if(ApplicationManager.getApplicationManager().isSystemLocked())
    	 {
     		UiApplication.getUiApplication().invokeLater(new Runnable() 
     		{	
 				public void run() 
 				{
 					Dialog.alert("LOCK");
 					
 				}
 			}) ;
     	 }
     	 else 
     	 {
     		 pushScreen(new MyScreen());
     	 }
	}


	public void batteryGood() {
		// TODO Auto-generated method stub
		
	}


	public void batteryLow() {
		// TODO Auto-generated method stub
		
	}


	public void batteryStatusChange(int status) {
		// TODO Auto-generated method stub
		
	}


	public void powerOff() {
		// TODO Auto-generated method stub
		
	}


	public void powerUp() 
	{
		removeSystemListener(this);
		doStartUpWork();
	}


	private void doStartUpWork() 
	{
		 if(ApplicationManager.getApplicationManager().isSystemLocked())
    	 {
     		UiApplication.getUiApplication().invokeLater(new Runnable() 
     		{	
 				public void run() 
 				{
 					Dialog.alert("LOCK");
 					
 				}
 			}) ;
     	 }
     	 else 
     	 {
     		 pushScreen(new MyScreen());
     	 }
	}    
}

 Try This Code, and let autoStartup be enabled..

 

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

And try to show screen in Thread it will definately help you..
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

Thanx for ur modified code,but its still not working the way i want it to 

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

 if(ApplicationManager.getApplicationManager().isSystemLocked())
    	 {
     		UiApplication.getUiApplication().invokeLater(new Runnable() 
     		{	
 				public void run() 
 				{
 					Dialog.alert("LOCK");
 					
 				}
 			}) ;
     	 }
     	 else 
     	 {
     		 pushScreen(new MyScreen());
     	 }

 Use this code in a Thread and start that thread in doStartUpWork() and in doStartUpWorkLater() method and then let me know is this working as u want

 

Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

As sugegsted by you to show the ,ain screen in a thread,id did something like this

 

 UiApplication.getUiApplication().invokeLater(new Runnable() {
				
				public void run() {
					 UiApplication.getUiApplication().pushScreen(new MyScreen());
					
				}
			});