根据子活动*将基于子活动的意图发送到主活动*不基于结果

时间:2015-11-26 23:13:01

标签: android android-intent android-activity

我有一项主要活动和6项儿童活动。我有条件,可以随时访问6个子活动中的5个,但打开第6个子活动的按钮只有在其他5个子活动打开后才会被点击。
为此,我在主活动中创建了一个5的布尔数组。单击5个始终可单击的按钮之一时,其关联的布尔变量将变为true。为了防止它在打开新活动时返回false,我将数组从主活动发送到子活动并使用Intents返回。我可以毫不费力地将阵列从主要阵列发送到孩子,但是我无法将它从子节点发送到主节点。以下是相关代码;

//MAIN ACTIVITY
//onClick method
public void openFirst(View view){
    opened[0] = true;
    Intent intent = new Intent(this, FirstChild.class);
    intent.putExtra("OpenIntent", opened);
    startActivity(intent);
}

//CHILD ACTIVITY
//onCreate method
protected void onCreate(Bundle savedInstanceState){
    open = getIntent().getBooleanArrayExtra("OpenIntent");
    //rest of oncreate method
}
//invoked by pressing back arrow 
public void onBackPressed(){
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("OpenIntent",open);
    super.onBackPressed();
}
//MAIN ACTIVITY
//onCreate method
protected void onCreate(Bundle savedInstanceState){
    opened = getIntent().getBooleanArrayExtra("OpenIntent")
    //rest of onCreate method
}

1 个答案:

答案 0 :(得分:0)

你做错了。如果您需要数据,那么您可以将其存储在SharedPreference并从那里进行访问,或者您可以在startActivityForResult()中使用MainActivity,同时启动childActivity并使用onBackPress()内部使用setResult() onActivityResult() 1}}用于检索FileOrig = "testtext{Number}"; for index_file in range(1, 2): fileName = FileOrig.format(Number = str(index_file)) ff = open(fileName, "rb") numline = 1; for line in ff: numline = numline + 1; position = ff.tell(); print(position); ff.close() 中的数据。

相关问题