GPS application gets killed on screen timeout

by sagar » Mon, 13 Apr 2009 12:03:54 GMT


Sponsored Links
 Hi ,

I can see on OMAP zoom2 platform, the moment screen timeout happens my
application is getting terminated. I have a Google map based LBS
application which is running on Zoom. I have implemented the
interfaces given in gps.h to libhardware_legacy/gps.cpp .

GPS application talks to android framework and Framework talks to
libhardware to get the GPS info. Now I can see that the moment screen
timeout happens and the display goes off, my application killed.
Actually from the framework the stop interface (hgps_stop() )  gets
called on screen timeout.

I am wondring why this is happening, as I am not sending any stop
request form my GPS application to the libhardware.

Is it something related to Android power manager, that android Power
manager does not know about my application is running?


Thanks and regards,
Saghar

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. ViewGroup's addChild() method stops being called after four touch events

Hi everybody!
I'am new to Android development and got stuck with one interesting
issue.
I've started implementing my own tree-like view, which will expand/
collapse its nodes as user taps on them. Every node in a tree is a
custom TextView(just for now) and there is two included ViewGroups to
hold those textviews together. ViewGroup forced me to override it's
onLayoutMethod() which in my case will call layout method on each
TextView node. Also used drawChild(Canvas canvas, View child, long
drawingTime) to pass drawing from viewgroup to it's children. Every
node(textview) implements View.OnTouchListener to handle touch events
and calls parent's requestLayout() method to force re-layout of tree
nodes. Everything seems to be working fine, but unfortunately for not
so long )) Problem is that drawChild() method get's invoked by system
only four times! Every next (on touch event from node) requestLayout()
call executes onLayout() as always but drawChild() never gets invoked
again, only app restart helps.
Application seems to be running normally and no exceptions are thrown
into the console.
Can anyone help solving limited paints problem ? Will appreciate any
comments or advices.

Here are my sources:
Node (one tree element)
----------
package com.example;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
import android.widget.TextView;

import java.util.Vector;


public class Node extends TextView implements View.OnTouchListener
{
    private Object data;
    private Vector children;
    private Node parentNode;

    private boolean isExpanded = true;

    public Node(Context context)
    {
        super(context);
        setOnTouchListener(this);
    }

    public Node(Context context, Object data)
    {
        this(context);
        setData(data);
        if (data instanceof String)
            setText((String) data);
    }
......

......

    @Override
    public void onDraw(Canvas canvas)
    {
        System.out.println("in node onDraw");
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        canvas.drawText((String) getData(), getLeft() + 10,
getBottom(), paint);
        if (!getChildren().isEmpty())
        {
            canvas.drawLine(getLeft(), getTop() + ((getBottom() -
getTop()) / 2) + 1, getLeft() + 8, getTop() + ((getBottom() -
getTop()) / 2) + 1, paint);
            if (!isExpanded)
                canvas.drawLine(getLeft() + 4, getTop() + 4, getLeft()
+ 4, getBottom(), paint);
        }
    }

    public boolean onTouch(View view, MotionEvent motionEvent)
    {
        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN)
        {
            isExpanded = !isExpanded;
            System.out.println("Expanded=" + isExpanded);
            ViewParent viewParent = view.getParent();
            viewParent.requestLayout();
            return true;
        }
        return false;
    }
}
------------------

SimpleTree(ViewGroup) which holds all Nodes:

------------------
package com.example;


import android.content.Context;
import android.graphics.Canvas;
import android.view.ViewGroup;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;

public class SimpleTree extends ViewGroup
{
    private Node rootElement;

    public SimpleTree(Context context)
    {
        super(context);
        rootElement = new Node(context, new Long(-1));
    }

    public void insertToTreeAsChild(Node parent, Node bufferTaskNode)
    {
        addView(bufferTaskNode);
        ....
    }

    public void insertToTreeAsSibling(Node parent, Node
bufferTaskNode, Node focusTaskNode)
    {
        addView(bufferTaskNode);
        ....
    }

    @Override
    public void onDraw(Canvas canvas)
    {
        paintElements(canvas, getRootElement());
    }

    private void paintElements(Canvas canvas, Node node)
    {
        if (!(node.getData() instanceof Long))
        {
            node.draw(canvas);
        }
        if (node.getChildren() != null && node.getChildren().size() !=
0 && node.isExpanded())
        {
            for (int i = 0; i < node.getChildren().size(); i++)
            {
                paintElements(canvas,
node.getChildren().elementAt(i));
            }
        }
    }

    @Override
    protected void onLayout(boolean b, int left, int top, int right,
int bottom)
    {
        layoutElements(getRootElement(), 0, 1);
    }

    private int layoutElements(Node node, int left, int top)
    {
        if (!(node.getData() instanceof Long))
        {
            node.layout(left * 15, top * 15, 50 + left * 15, top * 15
+ (int) node.getPaint().getTextSize());
        }
        if (node.getChildren() != null && node.getChildren().size() !=
0 && node.isExpanded())
        {
            top++;
            for (int i = 0; i < node.getChildren().size(); i++)
            {
                top = layoutElements(node.getChildren().elementAt(i),
left + 1, top + i);
            }
        }
        return top;
    }

}

------------------

TreeView(also ViewGroup) which operates on SimpleTree

-------------------
public class TreeView extends ViewGroup
{
    SimpleTree tree;

    public TreeView(Context context)
    {
        super(context);
        tree = new SimpleTree(context);
        addView(tree);
        tree.insertToTreeAsSibling(tree.getRootElement(), new
Node(context, "test1"), null);
        tree.insertToTreeAsChild(tree.findNode("test1"), new
Node(context, "test11"));
        tree.insertToTreeAsChild(tree.findNode("test11"), new
Node(context, "test111"));
        tree.insertToTreeAsChild(tree.findNode("test11"), new
Node(context, "test112"));
        tree.insertToTreeAsSibling(tree.getRootElement(), new
Node(context, "test2"), tree.findNode("test1"));
    }

    @Override
    protected void onLayout(boolean b, int i, int i1, int i2, int i3)
    {
        tree.onLayout(b, i, i1, i2, i3);
    }

    @Override
    protected boolean drawChild(Canvas canvas, View child, long
drawingTime)
    {
        tree.onDraw(canvas);
        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        return tree.dispatchTouchEvent(event);
    }
}
----------------------

And activity:

public class MLOActivity extends Activity
{
    public static final String GROUP_ID = "Group";
    public static final String CHILD_ID = "Child";
    public static final int GROUPS = 2;
    public static final int CHILDREN = 2;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        TreeView view = new TreeView(this);
        setContentView(view);
        view.invalidate();
    }
}

---------------------

Thanks in advance!


-- 

2. UDP Broadcast Receiver, work on old Phone, but not on new

I am seeing this same issue.  Have you found a solution?

On May 6, 2:01am, "marcomoel...@googlemail.com"


> 

3. Socket in AsyncTask - application crashesso the UI won't be blocked

4. Camera focus information?

5. How to uninstall application?

6. XML parsing differs on android and on desktop

7. Localization - new locale