×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Question How to make j2me app to run in background

    I am developing Loaction Alarm app in j2me. The purpose of my app is to alert user once he/she will reach to his/her desire location on which he/she set reminder.I want this must be happen when user close the app. For that I have to run my code in background which continuously check whether coordinates came from GPS is same as coordinates set in reminder. Once condition get true app will automatically prompt with an map(showing on Canvas) & alertbox or form(to show reminder text) with music tone. How should I done this???? Is any one done this before then plzz share your experience or code as soon as possible....

    Note: In app, Maximum 5 reminders user can set so that I have to check 5 reminders coordinates continuously & simultaneously.

    And I also want that when user close an app, excluding background running code other forms & controls should free the resources(i.e.should get delete) they are using & that should be again created when user start an app.
    Last edited by Rahul More; 2013-03-24 at 04:01.

  2. #2
    Registered User
    Join Date
    Mar 2013
    Posts
    14

    Re: How to make j2me app which run in background

    even my project is same like rahul more's project, i also want to know how to put j2me app to background processing. So please help us as soon as posible

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How to make j2me app which run in background

    Quote Originally Posted by Rahul More View Post
    I want this must be happen when user close the app. For that I have to run my code in background which continuously check whether coordinates came from GPS is same as coordinates set in reminder.
    What exactly do you mean by "when user close the app"?

    Once an app is closed, that's it: the end. No more code runs an everything is cleaned up automatically.

    If you want to push the application into the background (and not close it), then take a look at this thread. Please do make use of the search facility to find if your question has been answered before.

    Note that not all Java devices can run applications in the background. Basic rule: Series 40 - no background apps, Series 60 - apps can run in the background.

    To minimize resource usage in the background:
    • make sure anything that is closeable is closed (InputStreams, OutputStreams, RecordStores, etc.)
    • make sure that objects you no longer need are unreachable - delete references to the object by setting variables to null

    Don't run Threads continuously in the background - you'll kill the device's performance and the battery. Use Thread.sleep().

    Even better, don't use a Thread, use an event. If you're using the Location API, you can get location events delivered to you at intervals, if I remember correctly.


    Quote Originally Posted by swapnilsrk View Post
    even my project is same like rahul more's project, i also want to know how to put j2me app to background processing. So please help us as soon as posible
    You're questions are already being responded to here. There is no need to post the same question in multiple places.

  4. #4
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Re: How to make j2me app which run in background

    Thanx a lot grahamhughes for such a nice and detail suggestion. I understood what you said but my meaning of closing an app is to free the resources that is forms, canvas and on their appended controls like command button, choicegroup, textbox, textfield etc.
    I am not getting where should I define the code which is going to run background... In my Main midlet class or should I create another .java file to run this. Why I am asking this because that code required a continuous supply of current GPS coordinates from GPS to match with coordinates of place on which reminder is set, so when I close the app that code should continuously run...
    Last edited by Rahul More; 2013-03-14 at 15:05.

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How to make j2me app which run in background

    For now, I suggest you put it all in one class, while you get the basic code working, then think about re-structuring it later.

    Code:
    // this isn't compete code, just the basic elements...
    
    public class MyLocationMIDlet extends MIDlet implements CommandListener, ProximityListener {
    
        private static final float CLOSE_ENOUGH = 50.0;  // 50 metres
    
        private Display display = Display.getDisplay(this);
        private LocationProvider gps;
    
        public void startApp() {
            // must set something here
            display.setCurrent(someDisplayable);
        }
    
        public void commandAction(Command c, Displayable d) {
            // need to initialize these from somewhere...
            gps = getLocationProvider();
            Coordinates target = getTargetCoordinates();
    
            // now... ask for events when we get close to the target
            gps.addProximityListener(this, target, CLOSE_ENOUGH);
            // and go to background
            display.setCurrent(null);
        }
    
        // you need to provide these two, to implement ProximityListened
    
        // this gets called by the LocationProvider when we get close enough to one of the targets we've registered
        public void proximityEvent(Coordinates coordinates, Location location) {
            // move app to foreground
            display.setCurrent(display.getCurrent());
        }
    
        public void monitoringStateChanged(boolean isMonitoringActive) {
            // do something
        }
    }
    Don't try to run this... I've left a lot of code out for you to add... such as creating the initial screens, attaching Commands to the screens, checking which Command has been activated in the commandAction() method, obtaining the LocationProvider instance, and so on.

    Do take a look in the wiki, where you will find lots of example source code.

    Graham.

  6. #6
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Re: How to make j2me app which run in background

    I choose my target device as Nokia C5-00 or Nokia C5-5MP. I checked its specifications on website both mobile have A-GPS & GPS support. But, in reality is this mobile have good GPS support?? & Is this support background running ???

  7. #7
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How to make j2me app which run in background

    See my reply to your identical post.

    One post is enough, no need to post the same question in many places.

Similar Threads

  1. How to make an application run the background?
    By Ameya.joshi_cellensis in forum Symbian C++
    Replies: 3
    Last Post: 2012-07-04, 08:30
  2. how to make console application in j2me that runs in background
    By ritusingh in forum Mobile Java General
    Replies: 8
    Last Post: 2010-02-19, 04:45
  3. How to make transparetn background ??
    By EVIL nurd in forum Themes/Carbide.ui
    Replies: 7
    Last Post: 2007-05-01, 14:30
  4. How to make background transparent?
    By oslario in forum Symbian User Interface
    Replies: 1
    Last Post: 2005-08-04, 07:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •