-1

I have MainActivity.class which is basically grid view that contains all products. When user clicks on any of these products, then it will take him to the detail page where products details are listed.

I could able to see response object as a string and need to pass this string to the ProductDetailActivity.class, I have put a break point in ProductDetailActivity.class but it never comes there. I am not sure if I am missing something or doing something wrong.

MainActivity.class

final String URL = ".../productDetail.php";

    StringRequest postRequest = new StringRequest(Request.Method.POST, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                       // response string received successfully and displayed on the console.
                         VolleyLog.v("Response:%n %s", response);
                         Intent intent = new Intent(MainActivity.this,ProductDetailActivity.class);
                         intent.putExtra("jsonArray", response);
                         MainActivity.this.startActivity(intent);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                }
            }
    ) {
        @Override
        protected Map<String, String> getParams()
        {
            Map<String, String>  params = new HashMap<>();
            params.put("id", records.get(position).getId());
            return params;
        }
    };

    CustomVolleyRequest.getInstance(this).getRequestQueue().add(postRequest);

ProductDetailActivity.class

public class ProductDetailActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.productdetail);

    // break point placed in the following line, but never hit!
    String jsonArray = getIntent().getStringExtra("jsonArray");
  }
}

Update:

After I debug it carefully, MainActivity.this.startActivity(intent); that line of code gives me the following error:

Unable to find the explicit activity

casillas
  • 16,351
  • 19
  • 115
  • 215

2 Answers2

2

Have you declared ProductDetailActivity in your AndroidManifest.xml ?

< activity android:name="[path to you class].ProductDetailActivity.class" android:configChanges="keyboard|keyboardHidden" >
< /activity>

And, you make sure when you request to "URL = ".../productDetail.php";", onResponse function must be call

casillas
  • 16,351
  • 19
  • 115
  • 215
Khang Doan
  • 436
  • 3
  • 9
  • I have got the `Unable to find explicit activity` error message. But ProductActivityDetail.class in the same package. Should I still has to declare it in Manifest. – casillas Dec 04 '15 at 23:14
  • I understand the problem, so you should check your activity in your AndroidManifest.xml < activity android:name="[path to you class].ProductDetailActivity.class" android:configChanges="keyboard|keyboardHidden" > – Khang Doan Dec 04 '15 at 23:16
  • can you show me the package name of ProductDetailActivity class – Khang Doan Dec 04 '15 at 23:18
  • `package com.example.eye.texas`; – casillas Dec 04 '15 at 23:21
  • In AndroidManifest.xml, change your ProductActivityDetail of activity define to < /activity> After that, try again :) – Khang Doan Dec 04 '15 at 23:24
  • Why do you hide `keyboard`, is there any reason? – casillas Dec 04 '15 at 23:25
  • just my example :), i don't know what is you activity defined . You can read here about android:configChanges="keyboard|keyboardHidden http://stackoverflow.com/questions/7818717/why-not-use-always-androidconfigchanges-keyboardhiddenorientation – Khang Doan Dec 04 '15 at 23:28
0

This is how I do it:

Intent intent = new Intent(MainActivity.this,ProductDetailActivity.class);
Bundle extras = new Bundle();
extras.putString("jsonArray", response);
intent.putExtras(extras);
startActivity(intent);

Then you open it with:

Bundle extras = getIntent().getExtras();
String jsonArray = extras.getString("jsonArray");
Jay
  • 324
  • 2
  • 14
  • I just saw that the OP had their package name incorrect in the manifest. So I guess there was nothing wrong with the way that they were passing and retrieving the string. – Jay Dec 04 '15 at 23:30
  • How do you know it is incorrect? – casillas Dec 04 '15 at 23:39