Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing Data From an Activity to a Fragment in Android
    primarykey
    data
    text
    <p>I am very new to Java and Android programming. I am trying to figure out how to pass a bundle of variables from one activity through another Activity that uses setContentView to an xml file that is attached to a class that extends ListFragment. Basically, I want the data from the 1st activity to be able to be accessed by the Fragment that is accessed in the 2nd activity. I've been trying to research this to avail so far so please forgive me if the answer exists on here already.</p> <p>I have an activity called Login.java that does the following:</p> <pre><code>Intent intent = new Intent(this, ListActivity.class); Bundle varBundle = new Bundle(); varBundle.putString("companyKey",companyKey); varBundle.putString("techID",techID); varBundle.putString("userID",userID); varBundle.putString("startDate",startDate); intent.putExtras(varBundle); startActivity(intent); </code></pre> <p>In ListActivity.java, I have this so far:</p> <pre><code>public class ListActivity extends Activity { public String companyKey; public String techID; public String userID; public String startDate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle vars = getIntent().getExtras(); companyKey = vars.getString("companyKey"); techID = vars.getString("techID"); userID = vars.getString("userID"); startDate = vars.getString("startDate"); setContentView(R.layout.fragmentlist); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.list, menu); return true; } } </code></pre> <p>I set the content view to fragmentlist.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/titles" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.example.technicianappointmentlist.OrderList" /&gt; </code></pre> <p>Fragmentlist.xml is tied to OrderList.java. This is where I want the data from the bundle passed into ListActivity.java to be able to be accessed. </p> <pre><code>public class OrderList extends ListFragment { //THIS IS WHERE I WANT TO ACCESS THE VARIABLES PASSED INTO ListActivity.java public OrderList() { super(); // TODO Auto-generated constructor stub } @SuppressWarnings({ }) @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } } </code></pre> <p>Is this possible? Again I apologize if this is a rookie question but I haven't found the answer to this yet.</p> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload