Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic Keyword , Reinstallation Required
    text
    copied!<p>In my application I have an Activity" Model" in which i get a value 'n' from an edit text , I have declared this value n as static int . So , that i can access it inside any class of the Application.</p> <p>The problem is that when I restart my application without reinstalling it , the value of 'n' remains the same as it was in the first case . And this affects my output.</p> <p>I cannot use intent to send values because , the value is accessed randomly in the application even in classes that are not activities.</p> <p>Can u please tell , where I m wrong.?? </p> <pre><code>package com.integrated.mpr; import java.io.File; import android.app.Activity; import android.app.Dialog; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Model extends Activity implements OnClickListener{ EditText etPos; Button bmodel; static int n;//static variable to be used in other classes File folder ; File subfolder; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.inputpage); etPos = (EditText) findViewById(R.id.etpos); bmodel = (Button) findViewById(R.id.bModel); bmodel.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bModel: String check = etPos.getText().toString(); String check1 = etNs.getText().toString(); n = Integer.parseInt(check); Intent openAlternative = new Intent("com.integrated.mpr.ALTERNATIVE"); startActivity(openAlternative); break; } } } </code></pre> <p>If i first install my app , and enter value in the edittext as 2 , the value of n =2 ; If second time i run my app without installing it , even if i enter 3 in the edittext , value of n remains 2 Where is the twist??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload