Click here to Skip to main content
15,886,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an app that creates recursively multiple instance of an activity as it traverses a file system (one activity per folder). I retrieve data via Intent when moving forward in the activity stack (i.e. normal folder traversal). The apps runs well when i go from parent folder to child folder. I have problems going [back], because list of files/folders remains the same of the previous activity (the child). I don't want to retrieve again folder data from internet, so it' possible to keep track of previous activity state? Here's a piece of code of my activity. Thanks

Java
public class RisorseActivity extends DashboardActivity implements Observer {
private Docente docente;
private String get_response;
private String response;
//private HttpsClient client;

private ListView list;
private RelativeLayout progressLayout;
private ProgressBar progressBar;
private TextView txtMateriale;

private ArrayList<risorsa> risorseList;
private RisorseAdapter risAdapter;
private RisorseList risList;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_risorse);
    setTitleFromActivityLabel(R.id.title_text);

    list = (ListView) findViewById(R.id.ListRisorse);
    list.setClickable(true);


    Intent intent = getIntent();
    // vengono recuperati i parametri dalla activity chiamante
    docente = (Docente) intent.getSerializableExtra(getPackageName() + ".Docente");
    //cartella = (Insegnamento) intent.getSerializableExtra(pkg + ".Insegnamento");
    get_response = intent.getExtras().getString("get_response");
    response = intent.getExtras().getString("response");

    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView                int position, long index) {
            if (risorseList.get(position).getType().equalsIgnoreCase("Folder")) {
                Intent intRisorse = new Intent(getApplicationContext(), RisorseActivity.class);
                intRisorse.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
                intRisorse.putExtra(getPackageName() + ".Docente", docente);
                intRisorse.putExtra("get_response", risorseList.get(position).getURL()); 
                startActivity(intRisorse);
            } else if (risorseList.get(position).getType().equalsIgnoreCase("File")) {
                //--------------- DOWNLOAD DEL FILE-------------------
            }
        }
    });


    startRisorseService();
}


// Aggiorna la View della Activity popolando la lista dei docenti trovati
private void updateView() {

    this.risAdapter = new RisorseAdapter(this, this.risorseList);
    if (this.risAdapter != null) {
        this.list.setAdapter(this.risAdapter);

    } else {
        Toast.makeText(this, "Errore caricamento lista materiale",
                Toast.LENGTH_LONG).show();
    }
}

private void startRisorseService() {
    // risList conterrà il nostro modello dei dati (l'array di oggetti
    // Ricevimento)
    risList = RisorseList.getInstance();
    if (risList.countObservers() == 0)
        risList.addObserver(this); // aggiungiamo la nostra "View" come
                                    // osservatore del modello dati

    loginState = ((LoginState) getApplicationContext());

    Handler handler = new RisorseHandler();
            //IT IS THE TASK THATH RETRIEVE THE DATA
    RisorseService task = null;
    if (response != null){
        task = new RisorseService(handler, loginState, response);
    }else
        task = new RisorseService(handler, loginState);
    if (task != null)
        task.execute(get_response);
}

public void update(Observable observable, Object arg1) {
    if(observable instanceof RisorseList){ 
        // in quanto potremmo avere piu modelli dati
        // verifichiamo su quale modello è avvenuto un cambiamento dei dati
        // prima di effettuare il cast
        this.risorseList = ((RisorseList) observable).getData();
    }
            updateView();
    risList.deleteObserver(this);
}

public void onClickRefresh(View v) {
    startRisorseService();
}


@Override
protected void onResume(){
    super.onResume();

            // IF I UNCOMMENT THESE LINES IT WORK BUT RETRIEVE DATA FROM INTERNET AGAIN!!!
    /*if (risAdapter == null)
        startRisorseService();
    else{
        risAdapter.notifyDataSetChanged();

    }*/
    if (risAdapter != null)
    updateView();
}
}
Posted
Updated 27-Nov-11 14:51pm
v2

1 solution

Java
StartActivity(Response);


Put this line after

Java
Response=intent.getExtras().getString("response");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900