Local Service - How to actually invoke methods

by Paul Townsend » Tue, 10 Nov 2009 02:08:14 GMT


Sponsored Links
 Hi I have looked at the Api's demo for local service but it doesn't
show how to invoke methods on the service or activity. I got a service
that will start and stop a timer but it also laps so I want to send
the lap times back to the activity so it can be displayed in a custom
view graph. This is just a small part of the program I to write hence
the reason its in a service atm, I just want to understand how to call
methods from service to activity and vice versa.

--



Other Threads

1. How to get the point from click the google map

hello, I am not so sure about what is your problem, so if your problem
is detect which pixels has been touched:

(This code is not compiled, could have some errors, is just like an
idea)
class Map extends MapView
{
    public boolean onTouchEvent(MotionEvent ev)
    {
       int coor_x = ev.getX();
       int coor_y = ev.getY();

       //And if you want get the geografic point represented by these
pixels:
       GeoPoint point = this.getProjection().fromPixels(coor_x,
coor_y);


       return super.onTouchEvent(ev);
    }
}

Was that the solution to your problem?

-- 

2. Savin a class to SD

Hi, I'm trying to save a serializable class that I've created (Model)
but I don't know what I'm doing wrong because IOEXception is thrown,
can you help me please? here's the code:

                File f = new File("/sdcard/");
                File[] files = f.listFiles();
                String fitx = null;


                if(files!=null){
                    for(int i=0;i<files.length;i++){

                        File fitxer = files[i];
                        fitx =  fitxer.getName();

                        if((ID + ".obj").equalsIgnoreCase(fitx)){
                            entrada = new ObjectInputStream(new
FileInputStream("/sdcard/" + ID + ".obj"));
                            Model regAct = null;
                            Object aux = entrada.readObject();
                            while (aux!=null){
                                if (aux instanceof Model){
                                    regAct = (Model)aux;
                                    regAct.putCoef(coeficients);
                                }

                                ObjectOutputStream sortida = new
ObjectOutputStream(new FileOutputStream("/sdcard/" + ID + ".obj"));
                                sortida.writeObject(regAct);
                                sortida.close();
                                detect=1;
                            }
                        }else{

                            Model mod= new Model (coeficients, ID,
sourceImage);
                            ObjectOutputStream sortida = new
ObjectOutputStream(new FileOutputStream("/sdcard/" + ID + ".obj"));
                            sortida.writeObject(mod);
                            sortida.close();
                            detect=1;
                        }
                    }
                }
            } catch (StreamCorruptedException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }




And here's the class I've created:



import java.io.Serializable;

import android.graphics.Bitmap;

import java.util.Vector;

public class Model implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID =
-1948073164554864537L;
    private String nom;
    private int ID, n_models, ncoef=100;
    private Vector<double[]> models = new Vector<double[]>();
    private Bitmap foto;

    public Model(double[] x, int n) {
        models.add(x);
        this.ID = n;
        n_models=1;
    }
    public Model() {
        n_models=0;
    }
    public Model(double[] x, int n, Bitmap img) {
        models.add(x);
        this.ID = n;
        n_models=1;
        this.foto=img;
    }
    public Model(double[] x, String n, Bitmap img) {
        models.add(x);
        this.nom = n;
        n_models=1;
        this.foto=img;
    }

    public Bitmap getImg(){
        return foto;
    }
    public double getDist(double[]a){
        double x = 999999999;
        double y = 999999999;
        for (int i=0;i<n_models;i++){
            double[] b = models.get(i);
            x= euclidea(a,b);
            if (x < y){
                y=x;
            }
        }

        return y;
    }

    public String getNom(){
        return nom;
    }

    public int getID(){
        return ID;
    }

    public void putCoef(double[] x){
        models.add(x);
        n_models++;
    }
    public void putImg(Bitmap x){
        foto=x;
    }

    public void putNom(String n){
        this.nom=n;
    }

    public void putID(int x){
        this.ID=x;
    }

    public double manhattan(double [] a, double [] b){
        double dist = 0;
        for(int i=1; i<ncoef; i++){
            dist += Math.abs(a[i]-b[i]);
        }
        return dist;
    }
    public double euclidea(double [] a, double [] b){
        double dist = 0;
        for(int i=1; i<ncoef; i++){
            dist += Math.pow((double)(a[i]-b[i]),2.0);
        }
        return (double)Math.sqrt(dist);
    }

}


Thanks

-- 

3. OpenGL and Live Wallpapers

4. GPS worknig on emulator but not on atcual phone

5. Alarm interrupt waking up the phone after it is turned off.

6. How to popup menu on touch event.

7. perbedaan HH di charger dalam keadaan mati dan hidu