kakashi20
31/07/14, 23:15:36
Tengo este código que enviará una variable a un servicio web y devuelve una respuesta.
Este proceso lo hago con AsyncTask.
Al final del proceso, en funcion OnPostExecute, abren un AlertDialog que contiene un webview y me muestra una url.
Hasta aqui todo está bien.
El detalle es que el LogCat me muestra: The application May be doing too much work on its main thread..
No sé por qué ocurre esto, si el proceso que estoy haciendo en un subproceso distinto del principal, utilizando AsyncTask.
Alguien me puede ayudar?
Gracias
public class Donar extends Fragment {
ImageButton insertar;
String emailAdd;
String name;
ImageView x;
ProgressDialog pd;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View x = inflater.inflate(R.layout.donar, container, false);
// Capturo las variables que dejo en memoria, nombre y email
SharedPreferences sp1 = PreferenceManager.getDefaultSharedPreferences(getA ctivity().getApplicationContext());
emailAdd = sp1.getString("EMAILADDRESS", "");
name = sp1.getString("NAME", "");
//-----------------------------------------------
insertar=(ImageButton) x.findViewById(R.id.imageButton1);
insertar.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new Insertar(getActivity()).execute();
}
});
return x;
}
//Inserta los datos de las Personas en el servidor.
private String insertar(){
// Declaro variables
String response = "";
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
HttpPost httppost;
//-------------------------
httpclient=new DefaultHttpClient(); // abre la conexion con un cliente web
httppost= new HttpPost("http:xxxxx/insert.php"); // Url del Servidor a donde se envian las var post
//Añadimos nuestros datos en un arraylist
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email",emailAdd.toString().trim()));
nameValuePairs.add(new BasicNameValuePair("nombre",name.toString().trim()));
//---------------------------------------
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));// envio las variables
// capturo lo que devuelve, si no devolviera nada solo hago la ejecucion del httpclient sin el handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
response = httpclient.execute(httppost, responseHandler);
//----------------------------------------------------------------
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}
//AsyncTask para insertar Personas
class Insertar extends AsyncTask<String,String,String>{
private Activity context;
Insertar(Activity context){
this.context=context;
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String result = insertar();
return result;
}
@Override
protected void onPostExecute(String result) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Dona1Click - Patrocinador");
WebView wv = new WebView(getActivity());
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
if(pd.isShowing()&&pd!=null)
{
pd.dismiss();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
alert.setView(wv);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.show();
// Para colocar un loading
pd = ProgressDialog.show(getActivity(), "", "Loading...",true);
//--------------------------
}
}
}
07-31 16:56:51.136: I/Choreographer(1100): Skipped 37 frames! The application may be doing too much work on its main thread.
07-31 16:56:51.536: I/Choreographer(1100): Skipped 99 frames! The application may be doing too much work on its main thread.
07-31 16:56:52.216: I/Choreographer(1100): Skipped 61 frames! The application may be doing too much work on its main thread.
07-31 16:56:52.666: I/Choreographer(1100): Skipped 48 frames! The application may be doing too much work on its main thread.
07-31 16:56:52.896: I/Choreographer(1100): Skipped 57 frames! The application may be doing too much work on its main thread.
07-31 16:56:53.046: I/Choreographer(1100): Skipped 39 frames! The application may be doing too much work on its main thread.
07-31 16:56:54.286: I/Choreographer(1100): Skipped 45 frames! The application may be doing too much work on its main thread.
07-31 16:56:54.416: I/Choreographer(1100): Skipped 32 frames! The application may be doing too much work on its main thread.
07-31 16:56:54.556: I/Choreographer(1100): Skipped 35 frames! The application may be doing too much work on its main thread.
07-31 16:56:56.286: I/Choreographer(1100): Skipped 30 frames! The application may be doing too much work on its main thread.
07-31 16:56:57.006: I/Choreographer(1100): Skipped 98 frames! The application may be doing too much work on its main thread.
07-31 16:56:57.616: I/Choreographer(1100): Skipped 36 frames! The application may be doing too much work on its main thread.
Este proceso lo hago con AsyncTask.
Al final del proceso, en funcion OnPostExecute, abren un AlertDialog que contiene un webview y me muestra una url.
Hasta aqui todo está bien.
El detalle es que el LogCat me muestra: The application May be doing too much work on its main thread..
No sé por qué ocurre esto, si el proceso que estoy haciendo en un subproceso distinto del principal, utilizando AsyncTask.
Alguien me puede ayudar?
Gracias
public class Donar extends Fragment {
ImageButton insertar;
String emailAdd;
String name;
ImageView x;
ProgressDialog pd;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View x = inflater.inflate(R.layout.donar, container, false);
// Capturo las variables que dejo en memoria, nombre y email
SharedPreferences sp1 = PreferenceManager.getDefaultSharedPreferences(getA ctivity().getApplicationContext());
emailAdd = sp1.getString("EMAILADDRESS", "");
name = sp1.getString("NAME", "");
//-----------------------------------------------
insertar=(ImageButton) x.findViewById(R.id.imageButton1);
insertar.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new Insertar(getActivity()).execute();
}
});
return x;
}
//Inserta los datos de las Personas en el servidor.
private String insertar(){
// Declaro variables
String response = "";
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
HttpPost httppost;
//-------------------------
httpclient=new DefaultHttpClient(); // abre la conexion con un cliente web
httppost= new HttpPost("http:xxxxx/insert.php"); // Url del Servidor a donde se envian las var post
//Añadimos nuestros datos en un arraylist
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email",emailAdd.toString().trim()));
nameValuePairs.add(new BasicNameValuePair("nombre",name.toString().trim()));
//---------------------------------------
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));// envio las variables
// capturo lo que devuelve, si no devolviera nada solo hago la ejecucion del httpclient sin el handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
response = httpclient.execute(httppost, responseHandler);
//----------------------------------------------------------------
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}
//AsyncTask para insertar Personas
class Insertar extends AsyncTask<String,String,String>{
private Activity context;
Insertar(Activity context){
this.context=context;
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String result = insertar();
return result;
}
@Override
protected void onPostExecute(String result) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Dona1Click - Patrocinador");
WebView wv = new WebView(getActivity());
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
if(pd.isShowing()&&pd!=null)
{
pd.dismiss();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
alert.setView(wv);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.show();
// Para colocar un loading
pd = ProgressDialog.show(getActivity(), "", "Loading...",true);
//--------------------------
}
}
}
07-31 16:56:51.136: I/Choreographer(1100): Skipped 37 frames! The application may be doing too much work on its main thread.
07-31 16:56:51.536: I/Choreographer(1100): Skipped 99 frames! The application may be doing too much work on its main thread.
07-31 16:56:52.216: I/Choreographer(1100): Skipped 61 frames! The application may be doing too much work on its main thread.
07-31 16:56:52.666: I/Choreographer(1100): Skipped 48 frames! The application may be doing too much work on its main thread.
07-31 16:56:52.896: I/Choreographer(1100): Skipped 57 frames! The application may be doing too much work on its main thread.
07-31 16:56:53.046: I/Choreographer(1100): Skipped 39 frames! The application may be doing too much work on its main thread.
07-31 16:56:54.286: I/Choreographer(1100): Skipped 45 frames! The application may be doing too much work on its main thread.
07-31 16:56:54.416: I/Choreographer(1100): Skipped 32 frames! The application may be doing too much work on its main thread.
07-31 16:56:54.556: I/Choreographer(1100): Skipped 35 frames! The application may be doing too much work on its main thread.
07-31 16:56:56.286: I/Choreographer(1100): Skipped 30 frames! The application may be doing too much work on its main thread.
07-31 16:56:57.006: I/Choreographer(1100): Skipped 98 frames! The application may be doing too much work on its main thread.
07-31 16:56:57.616: I/Choreographer(1100): Skipped 36 frames! The application may be doing too much work on its main thread.