Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Ant+ Android SDK not release channel properly

Rank

Total Posts: 8

Joined 2017-04-26

PM

I'm using API
public static PccReleaseHandle<AntPlusHeartRatePccrequestAccess(Context bindToContextint antDeviceNumberint searchProximityThresholdIPluginAccessResultReceiver<AntPlusHeartRatePccresultReceiverIDeviceStateChangeReceiver stateReceiver
to connect Ant+ Sensors.

I found that if I close the PccReleaseHandle before the device connected, the channel would not be released.

If all 8 devices found and connected successfully, it works perfectly after I finish and reopen the activity.

But if the device not be found, or I leave the activity before some of them be found, then I will encounter CHANNEL_NOT_AVAILABLE error when I reopen the activity. I have to restart the application to make it work again.

I'm not sure if this behavior caused by some bug in SDK or just I misused the API?

Anybody has any idea?

Thanks.      
Rank

Total Posts: 8

Joined 2017-04-26

PM

my code below:

public class TrainingActivity extends Activity {
    
@Override
    
protected void onCreate(Bundle savedInstanceState{
      super
.onCreate(savedInstanceState);
      
setContentView(R.layout.training);
        
// connect 8 sensors with an 8-channel adapter
        
for (String sensorNumber sensorsToConnect()) {
            releaseHandles
.add(AntPlusHeartRatePcc.requestAccess(activitysensorNumber0accessResultReceiverdeviceStateChangeReceiver););
        
}
    }

    
@Override
    
protected void onDestroy() 
      for (
PccReleaseHandle releaseHandle releaseHandles{
        releaseHandle
.close();
      
}

      releaseHandles
.clear();
      
super.onDestroy(); 
     
Rank

Total Posts: 8

Joined 2017-04-26

PM

something wrong with the editor, have to remove some symbols in my code, or it not allow submit.      
Avatar
RankRankRankRank

Total Posts: 149

Joined 2014-04-02

PM

Digging up an old thread, but as I was recently following up on this same problem I will post.

Yes, this is a known issue. You should not use the release handle returned from requestAccess() because of this problem.

As a side note, you probably don't want to be managing your ANT+ connections from an Activity because of this. Use a Service. A started service will allow you to wait for the time needed to cleanup if the Activity onDestroy() happens during the connection, as well as adding better handling of phone configuration changes.

-Rohan      

Signature

blackramlabs.com

Rank

Total Posts: 5

Joined 2018-07-30

PM

arrgh - 07 May 2018 10:49 AM
Yes, this is a known issue. You should not use the release handle returned from requestAccess() because of this problem.
As a side note, you probably don't want to be managing your ANT+ connections from an Activity because of this. Use a Service.


Is it correct to the issue when I want to find any types of devices? In my situation I can't start searching at all, but using requestAccess() for each type may be not preferable to me.