0

I'm developing an android app where a data is send from one activity to another

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_project_details);

    final Intent data =this.getIntent();
    final String currentDocumentId = data.getStringExtra("clickedDocumentId");
    }

    public static String projectDocumentId(){
    return currentDocumentId;
    }

I don't know how to access the currentDocumentId variable outside onCreate(). How to do it?

data is non-static

1
  • Make it a global variable and set it within onCreate Commented Jun 24, 2020 at 16:21

1 Answer 1

1

Simply create a global variable at the top of your activity class, called currentDocumentId, note that it could be nullable.

private String currentDocumentId;
    
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_project_details);

    final Intent intent = getIntent();
    currentDocumentId = intent.getStringExtra("clickedDocumentId");
}

@Nullable
public String getCurrentDocumentId(){
    return currentDocumentId;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.