(Android) Which is better Bundle or Application?

I am working on an Android application that fetches data from a database. I want to pass data between activities (single line). I first implemented data transfer using the Bundle function. However, I came across an Application class that allows access to a variable from any activity.

What do you recommend using to move data between activities?

public class MyVideo extends Application {

  private String url ="NULL";

  public String getUrl(){
    return url;
  }
  public void setUrl(String newurl){
    url = newurl;
  }

      

}

+3


source to share


2 answers


It is similar to this question What is "bundle"? in the Android app which contains a comprehensive answer with an example.

My answer would be that you will use the package as that is what they were designed for and which are easy enough to use. The package supports String without any extra work, so I would say this makes it perfect.

Adding to intents



intent.putExtra("myKey",AnyValue);  

      

Receiving:

Bundle extras = intent.getExtras(); 
String tmp = extras.getString("myKey");

      

+4


source


The application class will behave like a singleton class in your context. You can pass data between activities using the single class itself. You don't need to use an application class if you want to pass data between activities.



Packet is preferred for I / O data transfer.

+1


source







All Articles