How to override connection to stop the application? [closed]

7

I have an Android application that sends data to a server via wireless, when sending changes from Activity B to A.

It turns out that when the connection is weak the application stops and gives the error below.

So I understand what I read in the SOen, because when I block my Activity B, you lose essential data that would be passed from Activity B to A and give the error.

Can anyone tell me a way to solve this?

PS: The process must be synchronous.

Error log:

  

09-30 14: 47: 22,999: E / Parcel (577): java.lang.ClassNotFoundException:   com.example.objects.myObject 09-30 14: 47: 22,999: E / Parcel (577): at   java.lang.Class.classForName (Native Method) 09-30 14: 47: 22,999:   E / Parcel (577): at java.lang.Class.forName (Class.java:251) 09-30   14: 47: 22.999: E / Parcel (577): at   java.lang.Class.forName (Class.java:216) 09-30 14: 47: 22,999:   E / Parcel (577): at   android.os.Parcel.readParcelableCreator (Parcel.java:2140) 09-30   14: 47: 22.999: E / Parcel (577): at   android.os.Parcel.readParcelable (Parcel.java:2104) 09-30 14: 47: 22,999:   E / Parcel (577): at android.os.Parcel.readValue (Parcel.java:2020) 09-30   14: 47: 22.999: E / Parcel (577): at   android.os.Parcel.readArrayMapInternal (Parcel.java:2321) 09-30   14: 47: 22.999: E / Parcel (577): at   android.os.Bundle.unparcel (Bundle.java:249) 09-30 14: 47: 22,999:   E / Parcel (577): at android.os.Bundle.getString (Bundle.java:1118) 09-30   14: 47: 22.999: E / Parcel (577): at   android.content.Intent.getStringExtra (Intent.java:5145) 09-30   14: 47: 22.999: E / Parcel (577): at   com.android.server.am.ActivityStackSupervisor.startActivityLocked (ActivityStackSupervisor.java:1466)   09-30 14: 47: 22,999: E / Parcel (577): at   com.android.server.am.ActivityStackSupervisor.startActivityMayWait (ActivityStackSupervisor.java:1061)   09-30 14: 47: 22,999: E / Parcel (577): at   com.android.server.am.ActivityManagerService.startActivityAsUser (ActivityManagerService.java:4067)   09-30 14: 47: 22,999: E / Parcel (577): at   com.android.server.am.ActivityManagerService.startActivity (ActivityManagerService.java:3965)   09-30 14: 47: 22,999: E / Parcel (577): at   android.app.ActivityManagerNative.onTransact (ActivityManagerNative.java:159)   09-30 14: 47: 22,999: E / Parcel (577): at   com.android.server.am.ActivityManagerService.onTransact (ActivityManagerService.java:2646)   09-30 14: 47: 22,999: E / Parcel (577): at   android.os.Binder.execTransact (Binder.java:404) 09-30 14: 47: 22,999:   E / Parcel (577): at dalvik.system.NativeStart.run (Native Method) 09-30   14: 47: 22,999: E / Parcel (577): Caused by:   java.lang.NoClassDefFoundError: with / example / objects / myObject 09-30   14: 47: 22,999: E / Parcel (577): ... 18 more 09-30 14: 47: 22,999:   E / Parcel (577): Caused by: java.lang.ClassNotFoundException: Did not   find class "with.example.objects.myObject" on path:   DexPathList [[directory "."], NativeLibraryDirectories = [/ vendor / lib,   / system / lib]] 09-30 14: 47: 22,999: E / Parcel (577): at   dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)   09-30 14: 47: 22,999: E / Parcel (577): at   java.lang.ClassLoader.loadClass (ClassLoader.java:497) 09-30   14: 47: 22.999: E / Parcel (577): at   java.lang.ClassLoader.loadClass (ClassLoader.java:457)

    
asked by anonymous 17.09.2015 / 17:50

3 answers

0

You can do this as follows. Create a Service to send your files, the service executes in the background. While the Service is sending the data you can view a ProgressDialog. When the submission is done, just tell the main activity to close the progress and move on to the next activity.

    
17.09.2015 / 20:27
0

You must execute this connection process with the server within a AsyncTask , because in case of delay the connection is running inside another Thread and not in the main.

Example:

Create a class that extends from AsyncTask , and inside doInBackground you make the whole process heavy.

 class MeuAsyncTask extends AsyncTask<Void, Void, Void>{  
      @Override  
      protected Void doInBackground(Void... params) {  

           // aqui você executa o seu processo de conexão com o servidor.

           return null;  
      }  
 }  

and to run you should make the following code:

MeuAsyncTask meuAsync = new MeuAsyncTask();
meuAsync.execute();
    
22.09.2015 / 22:20
0

You provided few details and insisted on a synchronous solution. Most Android features, like other operating systems, run on threads, which run asynchronously and independently.

I do not believe you will be able to make this connection in a totally synchronous way, but what you can do is simulate a synchronous behavior. I think of two ways to do this:

  • trigger a thread and monitor until it is completed; you can do this within a loop, but this consumes resources and is not the most appropriate way.
  • trigger a thread and set up a callback, a method that will execute when it completes and signal that execution can continue.
30.12.2015 / 01:53