-1

I have developed an Android App which runs on both a smartphone and a smartwatch in parallel. On both devices, (let's say) it reads certain sensor data, processes that data (calculate its mean), and then store that results. The watch sends this result to the phone so all storing takes place on the phone. I used buffer writer to write a number into a text file every 5 seconds.

Now after every 320 data items exchanges from watch to the phone, my app on the phone gets killed and I get "the name of the app" is unfortunately stopped as a message. I can't figure it what why they stop exactly after this time? The app running on the watch continues to work fine. However, I cannot store its data because it cannot communicate to the phone version so I get this message "the app is unfortunately stopped as a message" every time the watch sends a number to phone for storing. The app has one activity which has a service (foreground).

Could it be that there is a limit on the amount of data being shared?

The code on watch:

// Create a data map and put data in it
    private void increaseCounter() {
        PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/count");
        putDataMapReq.getDataMap().putInt(COUNT_KEY, count++); // I add current time here as well
        PutDataRequest putDataReq = putDataMapReq.asPutDataRequest();
        PendingResult<DataApi.DataItemResult> pendingResult =
                Wearable.DataApi.putDataItem(mGoogleApiClient, putDataReq);
    }

Code on phone (possible problematic area):

@Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        for (DataEvent event : dataEvents) {
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                // DataItem changed
                DataItem item = event.getDataItem();
                if (item.getUri().getPath().compareTo("/count") == 0) {
                    DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
                    updateCount(dataMap.getInt(COUNT_KEY));
                }
            } else if (event.getType() == DataEvent.TYPE_DELETED) {
                // DataItem deleted
            }
        }
    }
utengr
  • 3,225
  • 3
  • 29
  • 68
  • probably you need to disable some apps for some period, check if they stops 160 minutes. and all your apps stops at same time? – Divyesh Patel Dec 02 '16 at 13:50
  • 1
    Ask the authors of the custom ROM. Android does not routinely terminate the processes of all the apps, let alone do so by crashing them and showing the standard "unfortunately stopped" message. – CommonsWare Dec 02 '16 at 14:07
  • @Divyesh I have disabled all other apps. Only my developed apps are running. All 12 versions of my app (12 apps) stops exactly at the same time. I tested it for the last one week around 5 times and it does the same behavior. However, the ones running on the watch don't stop. – utengr Dec 02 '16 at 14:08
  • Then you need to check your service code. Post one of your service code for more understand9ng – Divyesh Patel Dec 02 '16 at 14:12
  • Its more than 1500 lines so its difficult to put it here unless I narrow down the problematic area. As suggested by the @CommonsWare, it could be something to do with the CUSTOM ROM. – utengr Dec 02 '16 at 14:13
  • To be clear, I misread your original question, and had not realized that "all the apps" meant multiple copies of your app. Without a [mcve], it will be difficult for anyone to really help you much, though. The stack trace that you get from LogCat would give you some clues. – CommonsWare Dec 02 '16 at 14:19
  • @CommonsWare Okay, I'll give it another try to narrow it down so I can post additional relevant information here. – utengr Dec 02 '16 at 14:28

1 Answers1

0

You have to use Service with StartForeground notification to be sure app is always working.

and try to use START_STICKY flag while staring.

UPDATE

You have to dealloc memory of dataevent:

  @Override
    public void onDataChanged(DataEventBuffer dataEvents) {

        try{
            for(DataEvent dataEvent: dataEvents){
                if(dataEvent.getType() != DataEvent.TYPE_CHANGED){
                    continue;
                }
////... code

 dataEvents.release();
}catch (Exception e){
            Log.v("SunshineWatchFace",e.getMessage());
        }
    }
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194