进行递归活动(类似于FileSystem) [英] Going back in a recursive activity (FileSystem like)

查看:73
本文介绍了进行递归活动(类似于FileSystem)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它遍历文件系统时会递归地创建活动的多个实例(每个文件夹一个活动).在活动堆栈中前进时,即通过普通文件夹遍历时,我通过Intent检索数据.当我从父文件夹转到子文件夹时,应用程序运行良好.我在返回[返回]时遇到问题,因为文件/文件夹列表与上一个活动(子级)相同.我不想再次从Internet检索文件夹数据,因此可以跟踪以前的活动状态吗?这是我的活动的一段代码.谢谢

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

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();
}
}

推荐答案

StartActivity(Response);



将这行放在
之后



Put this line after

Response=intent.getExtras().getString("response");


这篇关于进行递归活动(类似于FileSystem)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆