traduccion putextra intents intent example desde boton activity abrir android mobile galaxy

putextra - La actividad de Android se recrea a sí misma.



intents traduccion (13)

Mi aplicación normalmente funciona bien, hasta que me enfrento a un problema extraño en un dispositivo específico. Hay 2 actividades en la aplicación. Después de iniciar ActivityB dentro de ActivityA, ActivityA comienza sin ningún problema. Sin embargo, después de volver a la Actividad A con presionar el botón de hardware o llamar a finish (); Dentro de closeButton en ActivityB, ActivityA se vuelve a cargar. Vuelve a activar onCreate () y vuelve a cargar todo su contenido. Y no estoy cambiando la orientación del teléfono. Este extraño comportamiento solo aparece en 15 teléfonos de más de 1.000 descargas de aplicaciones.

Este problema solo ocurre en el Galaxy S3 Android OS 4.1.2. Y esto también es extraño.

¿Tienes alguna idea de por qué esto está sucediendo?

Cuando empiezo una nueva actividad dentro del botón de escucha de esta manera:

ActivityA.java (MesajlarListViewActivity)

public class MesajlarListViewActivity extends TrackedActivity { Context context = null; // contacts JSONArray JSONArray contacts = null; ArrayList<Message> productArray = new ArrayList<Message>(); private ProductAdapter adapter; private ListView productList; private Runnable viewOrders; private HoloProgressIndicator profilInfoProgress = null; ImageView kapatButton = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mesajlar_list); context = this; kapatButton = (ImageView) findViewById(R.id.kapat_button); /* kapat button onclick listener. */ // ================================================================================================================= kapatButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { // Set vibration on touch. KnetGenericClass.vibratePhone(context); finish(); } }); // ================================================================================================================= //Progress bar. profilInfoProgress = (HoloProgressIndicator) findViewById(R.id.profil_info_progress); // cheking internet connectivity. if(KnetGenericClass.checkInternetConnection(context)) { // start task! /* internet var ise web service baglantisi kurmaya baslayabiliriz. */ startActivityIndicatorWithThread(); } else { KnetGenericClass.printErrorMessage(context, "Bağlantı Hatası", "Lütfen internet bağlantınızı kontrol ediniz."); } productList = (ListView) findViewById(R.id.product_list); adapter = new ProductAdapter(this, R.layout.message_row, productArray); productList.setAdapter(adapter); // When user click a view on list view new page is appearing. productList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Set vibration on touch. KnetGenericClass.vibratePhone(context); /* Navigate to message detay activity class with ilan ID. */ Intent myIntent = new Intent(view.getContext(), MesajDetayActivity.class); myIntent.putExtra("messageID", productArray.get(position).getId()); startActivity(myIntent); // setting image of clicked message null. RelativeLayout relativeLayout = (RelativeLayout) view; ImageView unreadedImageView = (ImageView) relativeLayout.findViewById(R.id.unreaded_image); unreadedImageView.setImageResource(0); } }); } public class ProductAdapter extends ArrayAdapter<Message> { ArrayList<Message> items; public ProductAdapter(Context context, int textViewResourceId, ArrayList<Message> objects) { super(context, textViewResourceId, objects); this.items = objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { if(convertView == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = vi.inflate(R.layout.message_row, null); } ImageView unreadedImageView = (ImageView) convertView.findViewById(R.id.unreaded_image); TextView productName = (TextView) convertView.findViewById(R.id.product_name); TextView productDetail = (TextView) convertView.findViewById(R.id.product_detail); // TextView productDate = (TextView) // convertView.findViewById(R.id.product_date); TextView sentDate = (TextView) convertView.findViewById(R.id.product_date); productName.setText(items.get(position).getSender()); productDetail.setText(items.get(position).getTitle()); // String bodyNoHTML = items.get(position).getBody(); if(items.get(position).getIsReaded()) { unreadedImageView.setImageResource(0); } else { unreadedImageView.setImageResource(R.drawable.bluedot); } String dateStr = items.get(position).getSentDate(); try { sentDate.setText(dateStr.substring(6, 8) + "." + dateStr.substring(4, 6) + "." + dateStr.substring(0, 4) +" "+dateStr.substring(8, 10)+":"+dateStr.substring(10, 12)); } catch(Exception e) { sentDate.setText(""); } return convertView; } }// @end of product adapter class. /* web service''e baglanti kurulan methodu threadin icerisinde cagiriyoruz. */ public void startActivityIndicatorWithThread() { // ============================================================================================== // getting ilan details into arraylist. // setting up thread. viewOrders = new Runnable() { public void run() { getMessageListFromWebService(); } }; Thread thread = new Thread(null, viewOrders, "MagentoBackground"); thread.start(); profilInfoProgress.start(); // ============================================================================================== // @end of the thread declaration. } public void getMessageListFromWebService() { // Creating JSON Parser instance JSONParser jParser = new JSONParser(context); // getting JSON string from URL JSONArray jsonArray = jParser.getAuthorizedInfoFromUrlToJSONArray( WebServiceInfo.getKnetWebServiceLink()+"/API/Member/GetInboxMessageList", MainActivity.getAccessToken()); // if json is null then there is a problem. if(jsonArray == null) { // if json array is null then print error message. runOnUiThread(showAlertMessage); runOnUiThread(returnRes); return; } try { // Eger aranilan kritere gore ilan yok ise hata mesaji basiyoruz. if(jsonArray.length() == 0) { // if json array is null then print error message. runOnUiThread(showAlertIlanYokMessage); runOnUiThread(returnRes); return; } // looping through All Contacts for (int i = 0; i < jsonArray.length(); i++) { JSONObject c = jsonArray.getJSONObject(i); // Storing each json item in variable // String id = c.getString(TAG_ID); String id = c.getString("Id"); String sender = c.getString("Sender"); // String body = c.getString("Body"); String title = c.getString("Title"); String sentDate = c.getString("SentDate"); Boolean isReaded = c.getBoolean("IsRead"); Message productObject = new Message(id, sender, "", title, sentDate, isReaded); productArray.add(productObject); } } catch (Exception e) { Log.e("BACKGROUND_PROC", e.getMessage()); } runOnUiThread(returnRes); } // @end of thread. private Runnable returnRes = new Runnable() { public void run() { profilInfoProgress.stop(); adapter.notifyDataSetChanged();// refreshing data over adapter in // list view. } }; // @end of thread. private Runnable showAlertMessage = new Runnable() { public void run() { // Bu hata genelde linkteki problemden, servera ulasilamamasindan // veya timeouttan meydana gelir. Toast.makeText(getApplicationContext(), "Mesajlar alınamadı lütfen daha sonra tekrar deneyiniz.", Toast.LENGTH_LONG).show(); } }; private Runnable showAlertIlanYokMessage = new Runnable() { public void run() { // Bu hata aranilan kelimeye gore ilan bulunamazsa gelir. Toast.makeText(getApplicationContext(), "Mesajlar bulunamadı.", Toast.LENGTH_LONG).show(); } }; }

================================================== ======================

ActividadB.java (MesajDetayActivity.java)

public class MesajDetayActivity extends TrackedActivity { private HoloProgressIndicator profilInfoProgress = null; TextView titleTextView = null; TextView senderTextView = null; TextView dateTextView = null; WebView bodyWebView = null; Message messageObject = null; String messageID = null; ImageView kapatButton = null; Context context; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mesajdetaylari); context = this; kapatButton = (ImageView) findViewById(R.id.kapat_button); /* kapat button onclick listener. */ // ================================================================================================================= kapatButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { // Set vibration on touch. KnetGenericClass.vibratePhone(context); finish(); } }); // ================================================================================================================= //Progress bar. profilInfoProgress = (HoloProgressIndicator) findViewById(R.id.profil_info_progress); Bundle extras = getIntent().getExtras(); if(extras != null) { messageID = extras.getString("messageID"); } titleTextView = (TextView) findViewById(R.id.title_textview); senderTextView = (TextView) findViewById(R.id.sender_textview); dateTextView = (TextView) findViewById(R.id.date_textview); bodyWebView = (WebView) findViewById(R.id.mesaj_webView); // Show the ProgressDialog on this thread profilInfoProgress.start(); // Start a new thread that will download all the data new MakeItTask().execute(); } // Async task. private class MakeItTask extends AsyncTask<String, Void, Object> { protected Object doInBackground(String... args) { Log.i("MyApp", "Background thread starting"); // This is where you would do all the work of downloading your data // getting message detay /* connect to web service */ getMessageDetayFromWebService(); return null; } protected void onPostExecute(Object result) { // Pass the result data back to the main activity // TakipListeActivity.this.data = result; try { titleTextView.setText("Başlık: " + messageObject.getTitle()); senderTextView.setText("Gönderen: " + messageObject.getSender()); dateTextView.setText("Tarih: " + messageObject.getSentDate().substring(6, 8) + "." + messageObject.getSentDate().substring(4, 6) + "." + messageObject.getSentDate().substring(0, 4)); if(!messageObject.getBody().contains("img")) { bodyWebView.loadDataWithBaseURL(null, messageObject.getBody(), "text/html", "UTF-8", null); } } catch (Exception e) { Log.e(CONNECTIVITY_SERVICE, "Mesaj Detayi bilgileri basilamadi."); } profilInfoProgress.stop(); } } /* web service''e baglanti kurulan methodu threadin icerisinde cagiriyoruz. */ public void getMessageDetayFromWebService() { // Creating JSON Parser instance JSONParser jParser = new JSONParser(context); // getting JSON string from URL JSONObject jsonObject = jParser.getAuthorizedInfoFromUrlToJSONObject( WebServiceInfo.getKnetWebServiceLink()+"/API/Member/GetInboxMessage/" + messageID, MainActivity.getAccessToken()); // if json is null then there is a problem. if(jsonObject == null) { return; } try { String title = jsonObject.getString("Title"); String id = jsonObject.getString("Id"); String sender = jsonObject.getString("Sender"); String date = jsonObject.getString("SentDate"); String body = jsonObject.getString("Body"); messageObject = new Message(id, sender, body, title, date, true); } catch (Exception e) { Log.e("BACKGROUND_PROC", e.getMessage()); } }// @end of getIlanDetayFromWebService. }

Edit: No solo estas dos actividades tienen este problema, todas las actividades tienen el mismo comportamiento en algunos teléfonos.


¿Has intentado cambiar el modo de launchmode en el Manifiesto de Android? Intenta agregar esto a tu declaración de actividad:

android:launchMode="singleTask"

A continuación, intente usar startActivityForResult , en lugar de startActivity . Esto obligará a la Actividad A a llamar a su onActivityResult(int, int, Intent) cuando finalice la Actividad B, que puede omitir esta llamada (con errores) a onCreate . Luego, en la Actividad A, implemente el método para hacer algo (como imprimir una declaración de depuración):

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.i("Test", "Did this work???"); //TODO send notification to your server to verify this works? }


Creo que no es por el límite de la memoria.

https://www.box.com/s/7pd0as03bb8wwumuc9l9

Debe probar estas dos actividades y verificar si está sucediendo en este ejemplo también o no. Por favor comparta el contenido de su archivo AndroidManifest.xml también, le ayudará con la depuración.


Hay una configuración para desarrolladores de Android llamada "No guardar actividades". La descripción de esta opción es "Destruye cada actividad tan pronto como el usuario la abandone". Esto parece una buena descripción de lo que está viendo, y dado que solo lo está viendo en algunos teléfonos, la idea de que esto se deba a una configuración de sistema no predeterminada parece plausible.

Lo ideal sería que su aplicación aún funcionara en este escenario, incluso si fuera menos óptimo. Pero si esta configuración es un problema para su aplicación, es posible que desee documentar este problema para sus usuarios.


La actividad A usa el diseño R.layout.mesajlar_list

La actividad B usa el diseño R.layout.mesajdetaylari

Pero ambos tienen la siguiente línea de código:

kapatButton = (ImageView) findViewById(R.id.kapat_button);

¿En qué diseño se encuentra R.id.kapat_button? Usar el mismo id en diferentes diseños es algo muy arriesgado. No puedo garantizar que esté causando lo que estás viendo, pero es el tipo de cosa que puede causar un comportamiento extraño.


La documentación de la actividad ( http://developer.android.com/reference/android/app/Activity.html ) dice lo siguiente sobre el ciclo de vida de una actividad en segundo plano:

Una actividad en segundo plano (una actividad que no es visible para el usuario y ha sido pausada) ya no es crítica, por lo que el sistema puede detener su proceso de forma segura para recuperar memoria para otros procesos visibles o en primer plano. Si es necesario cancelar su proceso, cuando el usuario navegue de nuevo a la actividad (haciéndolo visible en la pantalla nuevamente), su método onCreate (Bundle) se llamará con el savedInstanceState que había suministrado previamente en onSaveInstanceState (Bundle) para que puede reiniciarse en el mismo estado en que el usuario lo dejó por última vez.

En otras palabras, ActivityA puede o no ser destruido por el sistema operativo mientras ActivityB está activo, por lo que esta situación debe manejarse en el código. Si se ha destruido ActivityA, se llamará a onCreate (Bundle), cuando el usuario presione el botón Atrás en ActivityB.



Puede intentar una cosa, proporcionar su diseño en onCreate() y hacer el resto del trabajo en onStart() ¿¿si funciona??

ME GUSTA:

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.show); }

y

@Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Log.i(TAG, "On Start ....."); }

Ver http://developer.android.com/reference/android/app/Activity.html


Quizás deberías usar

Intent startIntent = new Intent(view.getContext(), ActivityB.class); startActivity(startIntent); finish() ;

Y

Intent startIntent = new Intent(view.getContext(), ActivityA.class); startActivity(startIntent); finish() ;

Cada vez que retrocedes o te adelantas.


Recibí este problema recientemente, y esto me molesta. Creo que la solución alrededor de 2 opciones para comprobar, pero inútil.

Acerca de la configuración "No mantener las actividades" corregida aquí, utilicé este código para verificar si estaba marcado como opcional (mi dispositivo de prueba personaliza la base en la versión 2.3.5 y no muestra esta opción):

private boolean isAlwaysFinishActivitiesOptionEnabled() { int alwaysFinishActivitiesInt = 0; if (Build.VERSION.SDK_INT >= 17) { alwaysFinishActivitiesInt = Settings.System.getInt(getApplicationContext().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0); } else { alwaysFinishActivitiesInt = Settings.System.getInt(getApplicationContext().getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0); } if (alwaysFinishActivitiesInt == 1) { return true; } else { return false; } }

La comprobación de resultados es falsa en mi caso. También reviso la memoria al ejecutar la aplicación y no ocurre nada.


Reemplace los métodos onStart () y onResume en la Actividad A y verifique si el problema aún persiste. y si es posible, indique su código de actividad A y B aquí.


También enfrentó el problema exacto y resolvió el problema mediante el uso de android:launchMode="standard" en la activity del manifest .


Verifique si la opción No mantener las actividades en Configuración > Sistema > Opciones de desarrollador > Aplicaciones está habilitada o no.


puedes usar android:launchMode="singleTop" en el manifiesto.

<activity android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTop" android:configChanges="orientation|keyboardHidden|screenSize" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>