mardi 19 mai 2015

How to save passed data in text-view from other activity

I have Two Activity. First is MainActivity.java and second is slidelock.java. I am passing List-View items position of slide.java's to MainActivity.java with finish(). Data passed Perfectly but when i restart the app all passed data lost.

I want to store that data in text-view but I don't know how to store it with OnActivityResult()

MY main activity code of OnActivityResult()

 @Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

switch(requestCode) {
case 610:
    if (resultCode == RESULT_OK) {
        Bundle res = data.getExtras();

        int clickedRow = res.getInt("clicked_row");
        // Do what you want with that value..
        TextView tv = (TextView)findViewById(R.id.scl_desc);
        if(clickedRow == 0){
            Name = "clickedRow ";
            tv.setText(Name);

        }
        if(clickedRow == 1){
            Name = "clickedRow 2";
            tv.setText(Name);
            }
        if(clickedRow == 2){
            Name = "clickedRow 3";
            tv.setText(Name);
            }
        if(clickedRow == 3){
            Name = "clickedRow 4";
            tv.setText(Name);
            }
        if(clickedRow == 4){
            Name = "clickedRow 5";
            tv.setText(Name);
            }            
    }
    break;
    }
}

My slidelock.java code is

    public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
        int a = aimg.length;
            //View item = list.getAdapter().getView(position, view, parent);

            Intent  resultIntent = getIntent();
            resultIntent.putExtra("clicked_row", position);
            slidelock.this.setResult(Activity.RESULT_OK, resultIntent);                         
            //overridePendingTransition  (R.anim.right_slide_in, R.anim.right_slide_out);
            finish();



    // TODO Auto-generated method stub

    }
   });
}

Any One can help..??

Aucun commentaire:

Enregistrer un commentaire