@@ -41,7 +41,7 @@ public void onServiceConnected(ComponentName name, IBinder binder) {
4141 public void onServiceDisconnected (ComponentName name ) {
4242 service = null ;
4343 serviceConnected = false ;
44- initConnection (context , false );
44+ startInitConnection (context , false );
4545 for (ConnectionWrapper connectionWrapper : DeviceServiceConnector .getConnectionWrappers ()) {
4646 connectionWrapper .onPrinterServiceDisconnected ();
4747 }
@@ -56,36 +56,45 @@ public Boolean getServiceConnected() {
5656 return serviceConnected ;
5757 }
5858
59- public void initConnection (Context appContext , boolean force ) {
60- DeviceServiceOperationOnMainThreadException .throwIfMainThread ();
61-
62- if (appContext == null ) {
63- return ;
64- }
65- context = appContext ;
66- if (service == null || force ) {
67- Intent pr = new Intent (ACTION_PRINTER_SERVICE );
68- pr .setPackage (TARGET_PACKAGE );
69- pr .setClassName (TARGET_PACKAGE , TARGET_CLASS_NAME );
70- serviceConnected = null ;
71- boolean serviceBound = context .bindService (pr , serviceConnection , Service .BIND_AUTO_CREATE );
72- if (!serviceBound ) {
73- serviceConnected = false ;
59+ @ Override
60+ public void startInitConnection (final Context appContext , final boolean force ) {
61+ new Thread () {
62+ @ Override
63+ public void run () {
64+ if (appContext == null ) {
65+ return ;
66+ }
67+
68+ context = appContext ;
69+ if (service == null || force ) {
70+ Intent pr = new Intent (ACTION_PRINTER_SERVICE );
71+ pr .setPackage (TARGET_PACKAGE );
72+ pr .setClassName (TARGET_PACKAGE , TARGET_CLASS_NAME );
73+ serviceConnected = null ;
74+ boolean serviceBound = context .bindService (pr , serviceConnection , Service .BIND_AUTO_CREATE );
75+ if (!serviceBound ) {
76+ serviceConnected = false ;
77+ }
78+ }
7479 }
75- }
80+ }. start ();
7681 }
7782
78- public void deInitConnection () {
79- DeviceServiceOperationOnMainThreadException .throwIfMainThread ();
80-
81- if (context == null ) {
82- return ;
83- }
84- context .unbindService (serviceConnection );
85- service = null ;
86- for (ConnectionWrapper connectionWrapper : DeviceServiceConnector .getConnectionWrappers ()) {
87- connectionWrapper .onPrinterServiceDisconnected ();
88- }
83+ @ Override
84+ public void startDeinitConnection () {
85+ new Thread () {
86+ @ Override
87+ public void run () {
88+ if (context == null ) {
89+ return ;
90+ }
91+ context .unbindService (serviceConnection );
92+ service = null ;
93+ for (ConnectionWrapper connectionWrapper : DeviceServiceConnector .getConnectionWrappers ()) {
94+ connectionWrapper .onPrinterServiceDisconnected ();
95+ }
96+ }
97+ }.start ();
8998 }
9099
91100 public int getAllowableSymbolsLineLength (int deviceId ) throws DeviceServiceException {
0 commit comments