Java GetExtra Android赢得';行不通

Java GetExtra Android赢得';行不通,java,android,android-activity,get,Java,Android,Android Activity,Get,我是android世界的新手,所以我开始练习创建一个“Keep”应用程序。就像你想象的那样,我可以添加注释。问题是我的主要活动是: @Override protected void onResume() { super.onResume(); if (newNote) { newNote = false; findViewById(R.id.note)).setText(intentNewNote.getStringExtra("toto"));

我是android世界的新手,所以我开始练习创建一个“Keep”应用程序。就像你想象的那样,我可以添加注释。问题是我的主要活动是:

@Override
protected void onResume() {
    super.onResume();
    if (newNote) {
        newNote = false;
      findViewById(R.id.note)).setText(intentNewNote.getStringExtra("toto"));
    }
}

public void addNotes(View view) {
    newNote = true;
    intentNewNote = new Intent(this, newNote.class);
    startActivity(intentNewNote);
}
所以我有一个按钮调用onClick addNotes,这里是newNote类-

 @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.new_note);
    intent = this.getIntent();
}

 @Override
protected void onDestroy() {
    intent.putExtra("toto", "tototookiklojlojlllllllllllllllllllllllllllllto");
    super.onDestroy();
}
toto Extra是一种测试,但它无法打印,这样就可以工作了

 @Override
protected void onResume() {
    super.onResume();
    if (newNote) {
        newNote = false;
        intentNewNote.putExtra("toto", "dzazda");
        ((TextView) findViewById(R.id.note)).setText(intentNewNote.getStringExtra("toto"));
    }
}
因此,当我在另一个活动中添加额外的内容时,它不起作用。唯一的解释是,我在addNotes类上的意图不一样。 有人有主意吗


谢谢。

您是否使用putExtra来保存数据?我对你想做什么感到很困惑


为了创建Keep类型的应用程序,您需要某种类型的数据库/服务器。看看Parse或Firebase。

您是否使用putExtra来保存数据?我对你想做什么感到很困惑


为了创建Keep类型的应用程序,您需要某种类型的数据库/服务器。看看Parse或Firebase。

我试图了解您正在做什么,我相信您正在尝试从第二个活动返回一些信息,但您使用的是您收到的相同意图。它在android上的工作方式如下:

在第一个活动中,使用startActivityForResult()方法调用第二个活动

例如:

意向i=新意向(此,SecondActivity.class); startActivityForResult(i,1); 在第二个活动中,设置要返回第一个活动的数据。如果您不想返回,请不要设置任何

例如:在secondActivity中,如果要发回数据:

Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
setResult(Activity.RESULT_OK,returnIntent);
finish();
如果不想返回数据:

Intent returnIntent = new Intent();
setResult(Activity.RESULT_CANCELED, returnIntent);
finish();
已编辑

现在,在第一个Activity类中,为onActivityResult()方法编写以下代码


我试图了解你在做什么,我相信你在试图从第二次活动中返回一些信息,但你使用的是你收到的相同意图。它在android上的工作方式如下:

在第一个活动中,使用startActivityForResult()方法调用第二个活动

例如:

意向i=新意向(此,SecondActivity.class); startActivityForResult(i,1); 在第二个活动中,设置要返回第一个活动的数据。如果您不想返回,请不要设置任何

例如:在secondActivity中,如果要发回数据:

Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
setResult(Activity.RESULT_OK,returnIntent);
finish();
如果不想返回数据:

Intent returnIntent = new Intent();
setResult(Activity.RESULT_CANCELED, returnIntent);
finish();
已编辑

现在,在第一个Activity类中,为onActivityResult()方法编写以下代码


是的,这是因为当我搜索时,我发现这是在不同行为之间传递信息的最佳方式。但我会试着看看Parse和Firebase谢谢!是的,传递信息。这不是一种保存信息的方式。是的,这是因为当我搜索时,我发现这是在不同行为之间传递信息的最佳方式。但我会试着看看Parse和Firebase谢谢!是的,传递信息。这不是拯救它的一种形式。