How to avoid connection from stopping the application?

Asked

Viewed 121 times

7

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

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

I understand from what I read in Soen this happens because by blocking my Activity B essential data is lost that would be passed from Activity B to A and hence the error.

Can someone tell me a way to fix this?

PS: The process has to be synchronous.

Error log:

09-30 14:47:22.999: E/Parcel(577): java.lang.Classnotfoundexception: com.exemplo.objetos.meuObjeto 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/meObject 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: Didn’t find class "com.exemplo.objetos.meuObjeto" 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)

  • 1

    Put a catch Exception :P :D

  • 1

    @mustache your bad :P

  • That’s a small amount to help you. You’ll have to give more elements.

  • 1

    @ramaral I’m trying to reproduce. When I put more.

  • 1

    @ramaral already has the log.

  • Did the mistake happen in the same circumstances you described in the question? You know what it is com.sdilab.objectos.meuObjeto?

  • @ramaral yes is an object that I use in a list in activity A

  • @ramaral alias is the object selected in A then B will make some changes, then when sending to the server the application goes back to A with the object docked.

  • By editing the question I suppose now the error has arisen in another situation. Can you describe it? I was going to ask if this object was passed to the other Activity but you already answered. As it is a mistake that only happens from time to time will not be easy to resolve without knowing under what circumstances it happens.

  • The situation is the same @ramaral I was not able to explain well when I created the question. It only happens sometimes, yes when the network is weak, this is because I have two states in the app, offline and online and everything goes well. The problem appears when the network signal is too weak.

  • @but the client happens frequently. I’ve tried to have him send me his log, but what he sent me had no mistake.

  • @ramaral forgot to mention I have an external library that makes me uploads to the server, I just wait for the result of it and continue running my app.

  • You can put the part of the code that makes/ handles this request?

Show 8 more comments

3 answers

0

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

Example:

Create a class that extends from AsyncTask, and within theInBackground 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 must do the following code:

MeuAsyncTask meuAsync = new MeuAsyncTask();
meuAsync.execute();
  • Thank you for your reply but the process must be synchronous.

0

You have provided few details and insist on a synchronous solution. Much of the features of Android, as well as other operating systems, works with threads, which run independently and asynchronously.

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

  • shoot a thread and monitor until it is completed; you can do this within a loop, but it consumes resources and is not the most appropriate way.
  • trigger a thread and configure a callback, a method that will be executed when it is completed and will signal that execution can continue.

0

You can do it this way. Create a Service to send your files, the service runs in the background. While the Service is sending the data you can display a Progressdialog. When the upload is finished simply inform the main Activity to close the file and move to the next Activity.

  • Thank you for your reply but the process must be synchronous.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.