mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-23 16:40:08 +00:00
添加容错处理,service增加是否连接标志
Signed-off-by: guojin26 <guojin26@huawei.com>
This commit is contained in:
parent
0076df13d0
commit
4fbb9046c1
@ -40,10 +40,13 @@ public class RemoteAbility extends Ability {
|
||||
RemoteAgentStub remoteAgentStub = new RemoteAgentStub(DESCRIPTOR) {
|
||||
@Override
|
||||
public void setRemoteObject(String param) throws RemoteException {
|
||||
showTips(RemoteAbility.this, param);
|
||||
if(isConnected) {
|
||||
showTips(RemoteAbility.this, param);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private boolean isConnected = false;
|
||||
@Override
|
||||
protected void onStart(Intent intent) {
|
||||
super.onStart(intent);
|
||||
@ -60,12 +63,14 @@ public class RemoteAbility extends Ability {
|
||||
@Override
|
||||
protected IRemoteObject onConnect(Intent intent) {
|
||||
showTips(RemoteAbility.this, "RemoteService onConnect");
|
||||
isConnected = true;
|
||||
return remoteAgentStub;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisconnect(Intent intent) {
|
||||
super.onDisconnect(intent);
|
||||
isConnected = false;
|
||||
showTips(RemoteAbility.this, "RemoteService onDisconnect");
|
||||
}
|
||||
|
||||
|
@ -114,19 +114,29 @@ public class MainAbilitySlice extends AbilitySlice implements IAbilityContinuati
|
||||
Component continueFAButton = findComponentById(ResourceTable.Id_continue_fa_button);
|
||||
connectRemotePAButton.setClickedListener(component -> connectService());
|
||||
disconnectRemotePAButton.setClickedListener(component -> disConnectAbility());
|
||||
continueFAButton.setClickedListener(component -> continueAbility(selectDeviceId));
|
||||
continueFAButton.setClickedListener(component -> continueFA());
|
||||
|
||||
text = (Text) findComponentById(ResourceTable.Id_text);
|
||||
text.setText(param);
|
||||
|
||||
}
|
||||
|
||||
private void continueFA() {
|
||||
try {
|
||||
continueAbility(selectDeviceId);
|
||||
} catch (IllegalArgumentException e) {
|
||||
HiLog.info(LABEL_LOG, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void disConnectAbility() {
|
||||
disconnectAbility(connection);
|
||||
try {
|
||||
DeviceManager.unInitDistributedEnvironment(selectDeviceId,iInitCallback);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
HiLog.info(LABEL_LOG, e.getMessage());
|
||||
}
|
||||
remoteAgentProxy = null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user