title: Android start activity after long time on minimize
body: <p>After user goes to other application, my application is not closed (as general, it is minimized)  but after some time when I open application it crashes, because NullPointerException.That is because android cleans some memory and some variables are not accessible any more. Is there any way to determine if android cleared memory of my app ? Or what is good solution to fight this issue</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_add_payment);
      Bundle bundle = getIntent().getExtras();
      personId = bundle.getInt("personId");
      personName = bundle.getString("personName");
  
      lendStr = getResources().getString(R.string.lend);
      borrowStr = getResources().getString(R.string.borrow);
  
  
      setUpViews();
  }
  
  
  private void setUpViews() {
      SqlHelper db = new SqlHelper(this);
      Helper.centerActionBarTitle(this, db.getPerson(personId).getName(), false);
      tf = Typeface.createFromAsset(getAssets(), "FLEXO.TTF");
      tfFlexo = Typeface.createFromAsset(getAssets(), "FLEXO_BOLD.TTF");
  
      iv_add_row = (ImageView) findViewById(R.id.iv_add_row);
      iv_remove_row = (ImageView) findViewById(R.id.iv_remove_row);
      et_amount = (EditText) findViewById(R.id.et_amount);
      et_item_name = (EditText) findViewById(R.id.et_item_name);
      et_quantity = (EditText) findViewById(R.id.et_quantity);
      et_price = (EditText) findViewById(R.id.et_price);
      et_total_price = (TextView) findViewById(R.id.et_total_price);
      tv_currency = (TextView) findViewById(R.id.tv_currency);
  
  
  
      et_item_name.setText(getResources().getString(R.string.item));
      et_quantity.setText(getResources().getString(R.string.qty));
      et_price.setText(getResources().getString(R.string.price));
      et_total_price.setText(getResources().getString(R.string.total));
  
      tv_break = (TextView) findViewById(R.id.tv_break);
      tv_payment_date = (TextView) findViewById(R.id.tv_payment_date);
      tv_p_date = (TextView) findViewById(R.id.tv_p_date);
      tv_p_time = (TextView) findViewById(R.id.tv_p_time2);
      tv_maturity = (TextView) findViewById(R.id.tv_maturity);
      tv_m_time = (TextView) findViewById(R.id.tv_m_time);
      tv_m_date = (TextView) findViewById(R.id.tv_m_date);
  
      ll_list_wrapper = (LinearLayout) findViewById(R.id.ll_list_wrapper);
  
      tv_operation_type = (TextView) findViewById(R.id.tv_operation_type);
      chk_break_items = (ImageView) findViewById(R.id.chk_break_items);
  
      et_item_name.setTypeface(tfFlexo);
      et_quantity.setTypeface(tfFlexo);
      et_price.setTypeface(tfFlexo);
      et_total_price.setTypeface(tfFlexo);
      tv_operation_type.setTypeface(tf);
      tv_currency.setTypeface(tf);
      tv_break.setTypeface(tf);
      tv_payment_date.setTypeface(tf);
      tv_p_date.setTypeface(tf);
      tv_p_time.setTypeface(tf);
      tv_maturity.setTypeface(tf);
      tv_m_time.setTypeface(tf);
      tv_m_date.setTypeface(tf);
  
      int currencyIndex = MainActivity.settings.getCurrency();
      tv_currency.setText(Constants.currencies[currencyIndex]);
  }
  </code></pre>
  
  <p>Logcat output:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.lionshare.aldkan/com.lionshare.aldkan.AddPayment}:
    java.lang.NullPointerException<br/> &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.ActivityThread.access$600(ActivityThread.java:151)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.os.Handler.dispatchMessage(Handler.java:99)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.os.Looper.loop(Looper.java:155)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.ActivityThread.main(ActivityThread.java:5511)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    java.lang.reflect.Method.invokeNative(Native Method)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    java.lang.reflect.Method.invoke(Method.java:511)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at dalvik.system.NativeStart.main(Native
    Method)<br/> Caused by: java.lang.NullPointerException<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    com.lionshare.aldkan.AddPayment.setUpViews(AddPayment.java:188)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    com.lionshare.aldkan.AddPayment.onCreate(AddPayment.java:114)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.Activity.performCreate(Activity.java:5066)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;... 11 more<br/></p>
  </blockquote>
  
  <p>Actyually, at <code>com.lionshare.aldkan.AddPayment.setUpViews(AddPayment.java:188)</code> is</p>
  
  <pre><code>MainActivity.settings.getCurrency()
  </code></pre>
  
  <p>It can't find static variable <code>settings</code> of <code>MainActivity</code>. I think the variable was cleared from memory.</p>