2
I have a problem in which information such as "name", "address" and "phone" that I type inside the EditText
of Activity
main disappear when I go to another Activity
seek other types of information and go back to the main one containing the EditText
.
I have tried using this setting:
... android:configChanges="orientation|keyboard|keyboardHidden">
Yet the data from Activity
major sum.
Why this happens and how can I solve it?
Activity
leading:
public class ServicoDeEmailActivity extends ActionBarActivity {
Session session = null;
ProgressDialog pdialog = null;
Context context = null;
String rec;
String subject;
String textMessage;
EditText editTextValorDoPedido;
TextView txtValorTotalDoPedido;
double valorDoPedido;
int dados;
String nomeDoProduto;
String descricaoDoProduto;
int quantidadeDoProduto;
double precoUnitarioDoProduto;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_servico_de_email);
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
context = this;
final EditText nome;
final EditText rua;
final EditText numero;
final EditText complemento;
final EditText bairro;
App app = (App) getApplicationContext();
ItemCompra itemCompra = new ItemCompra();
Log.i("ServicoDeEmailActivity", "Entrou no metodo onCreate()");
final EditText telefone1 = (EditText) findViewById(R.id.telefone1);
telefone1.addTextChangedListener(Mask
.insert("(##)####-####", telefone1));
final EditText telefone2 = (EditText) findViewById(R.id.telefone2);
telefone2.addTextChangedListener(Mask
.insert("(##)####-####", telefone2));
final EditText cep = (EditText) findViewById(R.id.cep);
cep.addTextChangedListener(Mask.insert("#####-###", cep));
Button botao = (Button) findViewById(R.id.botaoIrParaProdutos);
botao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("ServicoDeEmailActivity", "Passou pelo metodo onClick()");
Log.i("ServicoDeEmailActivity", "Chamando Lista de produtos");
Intent irParaListaDeProdutos = new Intent();
irParaListaDeProdutos.setClass(ServicoDeEmailActivity.this,
ProdutoActivity.class);
startActivity(irParaListaDeProdutos);
Log.i("ServicoDeEmailActivity", "Lista de produtos chamada!");
}
});
nome = (EditText) findViewById(R.id.nome);
rua = (EditText) findViewById(R.id.rua);
numero = (EditText) findViewById(R.id.numero);
complemento = (EditText) findViewById(R.id.complemento);
bairro = (EditText) findViewById(R.id.bairro);
Intent intentRecuperaDadosDaLista = getIntent();
Bundle parametroDadosDaLista = intentRecuperaDadosDaLista.getExtras();
if (parametroDadosDaLista != null) {
nomeDoProduto = parametroDadosDaLista.getString("nomeDoProduto");
descricaoDoProduto = parametroDadosDaLista.getString("descricaoDoProduto");
precoUnitarioDoProduto = parametroDadosDaLista.getDouble("precoUnitarioDoProduto");
quantidadeDoProduto = parametroDadosDaLista.getInt("quantidadeDoProduto");
}
Button btnEnviarPedidoParaEmail = (Button) findViewById(R.id.botaoEnviaPedido);
btnEnviarPedidoParaEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rec = "DIGITE O EMAIL DE QUEM IRÁ RECEBE-LO";
subject = "Pedido Solicitado";
textMessage = "Nome: " + nome.getText()
+ "<br />" + "Rua: " + rua.getText()
+ "<br />" + "Número: " + numero.getText()
+ "<br />" + "Complemento: " + complemento.getText()
+ "<br />" + "Bairro: " + bairro.getText()
+ "<br />" + "CEP: " + cep.getText()
+ "<br />" + "Telefone: " + telefone1.getText()
+ "<br />" + "Celular: " + telefone2.getText()
+ "<br />" + "Valor total do Pedido: " + CurrencyUtils.format(BigDecimal.valueOf(valorDoPedido))
+ "<br />" + "-------------------------------"
+ "<br />" + "Lista de itens solicitados:"
+ "<br />" + "Produto: " + nomeDoProduto
+ "<br />" + "Descrição :" + descricaoDoProduto
+ "<br />" + "Preço unitário: " + CurrencyUtils.format(BigDecimal.valueOf(precoUnitarioDoProduto))
+ "<br />" + "Quantidade :" + quantidadeDoProduto;
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("DIGITE O EMAIL AQUI", "DIGITE A SENHA AQUI");
}
});
pdialog = ProgressDialog.show(context, "", "Enviando o pedido para o email...", true);
RetreiveFeedTask task = new RetreiveFeedTask();
task.execute();
}
class RetreiveFeedTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(rec));
message.setSubject(subject);
message.setContent(textMessage, "text/html; charset=utf-8");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
pdialog.dismiss();
Toast.makeText(getApplicationContext(), "Pedido enviado com sucesso!", Toast.LENGTH_SHORT).show();
}
}
});
txtValorTotalDoPedido = (TextView) findViewById(R.id.txt_valor_total);
Intent intent = getIntent();
Bundle params = intent.getExtras();
if (params != null) {
this.valorDoPedido = params.getDouble("ValorDoProduto");
txtValorTotalDoPedido.setText(CurrencyUtils.format(BigDecimal.valueOf(valorDoPedido)));
}
}
}
And the layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/layoutTodo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewProdutos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/nome_" />
<EditText
android:id="@+id/nome"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/rua_" />
<EditText
android:id="@+id/rua"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/n_mero_" />
<EditText
android:id="@+id/numero"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/complemento_" />
<EditText
android:id="@+id/complemento"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/bairro_" />
<EditText
android:id="@+id/bairro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/cep_" />
<EditText
android:id="@+id/cep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/telefone_1_" />
<EditText
android:id="@+id/telefone1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="phone" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/telefone_2_" />
<EditText
android:id="@+id/telefone2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="phone" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/botaoIrParaProdutos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lista de Produtos" />
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/total_r_" />
<TextView
android:id="@+id/txt_valor_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="normal"/>
</LinearLayout>
<Button
android:id="@+id/botaoEnviaPedido"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enviar Pedido" />
</LinearLayout>
</ScrollView>
At some point you change the orientation of Device
– ramaral
No ramaral, I haven’t changed the orientation
– Eric Andrade
In principle this should only happen if there was a change of orientation of the device or Android destroyed your Activity. I tried to understand his code but he’s very confused.
– ramaral