How do you handle loss of connectivity?

1116
7
Jump to solution
04-23-2013 10:14 PM
MatejSkerjanc
Occasional Contributor
Hello,

I've got an ArcGISFeatureLayer.applyEdits(-) with onError and onCallback...Why isnt onError called when i lose connection?

Any hints would be appreciated


Regards,
Matej
0 Kudos
1 Solution

Accepted Solutions
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
I create a BroadCastReceiver() implement the ConnectivityManager Class.  The BroadCastReceiver listens for changes in network state.  If the change is a loss of connectivity then I inflate a layout over my map.  when connectivity comes back, the layout closes.

             BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {                     @Override                     public void onReceive(Context context, Intent intent) {                         boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);                                     if (noConnectivity==true){                              findViewById(R.id.LostConnection).setVisibility(View.VISIBLE);                                 Button noConnExitBtn = (Button) findViewById(R.id.btnNoConnExit);                             noConnExitBtn.setOnClickListener(new OnClickListener(){                                 @Override                                 public void onClick(View arg0) {                                     GrotonViewerActivity.this.finish();                                                         }                                         });                           }else{                             findViewById(R.id.LostConnection).setVisibility(View.GONE);                             }                         Log.w("Network Listener", "Network Type Changed");                     }                 };                   IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);                         registerReceiver(networkStateReceiver, filter);                          setContentView(R.layout.main);

View solution in original post

0 Kudos
7 Replies
MatejSkerjanc
Occasional Contributor
Another question how do you handle the loss of connection during the initialization of arcgis layer?

ArcGISFeatureLayer remoteLayer = new ArcGISFeatureLayer(layerUrl,MODE.SNAPSHOT);
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
I create a BroadCastReceiver() implement the ConnectivityManager Class.  The BroadCastReceiver listens for changes in network state.  If the change is a loss of connectivity then I inflate a layout over my map.  when connectivity comes back, the layout closes.

             BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {                     @Override                     public void onReceive(Context context, Intent intent) {                         boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);                                     if (noConnectivity==true){                              findViewById(R.id.LostConnection).setVisibility(View.VISIBLE);                                 Button noConnExitBtn = (Button) findViewById(R.id.btnNoConnExit);                             noConnExitBtn.setOnClickListener(new OnClickListener(){                                 @Override                                 public void onClick(View arg0) {                                     GrotonViewerActivity.this.finish();                                                         }                                         });                           }else{                             findViewById(R.id.LostConnection).setVisibility(View.GONE);                             }                         Log.w("Network Listener", "Network Type Changed");                     }                 };                   IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);                         registerReceiver(networkStateReceiver, filter);                          setContentView(R.layout.main);
0 Kudos
MatejSkerjanc
Occasional Contributor
I did it almost identically. But the problem is the interval for receiver check is a bit slow.
Anyhow when i lose conn during applyEdits or query i usually dont even get an error. I mean it doesn't go into onError.
Is there a specific mechanism behind it or am i just doing it wrong somehow?
Thank you sir!
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
Interesting....  Just so I understand you: So, you're applying an edit (sending it to the server) and you lose connection.  Since you lose the connection I would imagine the API doesn't know what to do (onSuccess,onError) because it doesn't know what happened to the edit.  Does ArcGIS Server receive your edit?

This thought just popped into my head.  What if you created an enumerated property?  Call it something like EditStatus with enumerations of: Sent, Recieved,None.  Then check that with the broadcastReciever.  When connectivity changes, check the status of the EditStatus property.  If it's still set to "Send" then you sent your edit but it never came back.  when it's recieved (onSuccess/onError) reset the property to received. 

I'm not sure if it'd work, or if the logic is even valid.   Maybe this is something (somehow) you should log with Esri as an enhancement request.
0 Kudos
MatejSkerjanc
Occasional Contributor
The edits dont get to the server.
And if i reestablish connection (i lose it deliberetely) it sends the data.
Thanks for your time so far, i'll see if i keep getting this issue and if it actually becomes serious issue i'll propagate this to ESRI i guess.


Thank for suggestions and time!

Regards,
Matej
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
Might want to give Esri a call.  it's interesting how if you deliberately drop the connection it's "stored" on the device, but an inadvertent loss is never re-sent.  I think it's worth an inquiry.
0 Kudos
MatejSkerjanc
Occasional Contributor
by stored on the device ....well about this...we're making an offline editing that's why it's stored.
I guess i wasnt really clear on this. We're making offline editing. And when we send the changes to the server and deliberetely drop conn it doesn't go in onError. But for a little update: i've managed to get it under control. I think the problem was i had chained callbacks and a bit messy code and didnt follow the code path ...well till now.

Again thanks for your time and sorry for the incovenience Andrew
0 Kudos