Question

I have an activity which creates a unique ID and then passes the String to a service, the problem I am having is that the app force-closes every time I try passing the data from the activity to the service.

Normally when I am programming java applications I just use getter and setter methods to pass data between classes, so does anyone have an idea why this problem is occurring?

public void setId(String mydeviceId){

    TelephonyManager tm = (TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
    final String DeviceId, SerialNum, androidId;
    DeviceId = tm.getDeviceId();
    SerialNum = tm.getSimSerialNumber();
    androidId = Secure.getString(getContentResolver(),Secure.ANDROID_ID);
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long)DeviceId.hashCode() << 32) | SerialNum.hashCode());
    mydeviceId = deviceUuid.toString(); 
    this.mydeviceId = mydeviceId;   

    }


    public String getId(){

        return mydeviceId;

    }
Was it helpful?

Solution

Pass between classes means activities? If so, you need to use Intent bundle. Get/set wont work between activities. Here is an example how to pass data between activities.

OTHER TIPS

In order to communicate with your service, allow your Activity to bind with it. Refer to this guide. Its is the recommended way.

Alternatively, you may broadcast your desired values to communicate between Service and/or Activity. For more info, refer to this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top