-3

I have two Class page1 and page2. How can i transfer data from page1 to integer in page2 when the button in page1 is clicked

I've tried a couple codes: Page1.Class

protected void onListItemClick(ListView l, View v, int position, long id) {
        Intent i = null;
        switch (position) 
        {
        case 0:
            i = new Intent(this, page2.class );
        i.putExtra("Konum", 2);
        break;

        }
        startActivity(i);

Page2.Class

Intent intent = getIntent();
    private Integer konum = intent.getIntExtra("Konum", 0);

But doesnt work ! How can i transfer data from page1 to integer in page2 when the button in page1 is clicked

EROR :

    09-27 19:50:19.556: E/AndroidRuntime(528): FATAL EXCEPTION: main
09-27 19:50:19.556: E/AndroidRuntime(528): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ru.truba.touchgallery/ru.truba.touchgallery.GalleryUrlActivity}: java.lang.NullPointerException
09-27 19:50:19.556: E/AndroidRuntime(528):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
09-27 19:50:19.556: E/AndroidRuntime(528):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-27 19:50:19.556: E/AndroidRuntime(528):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-27 19:50:19.556: E/AndroidRuntime(528):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-27 19:50:19.556: E/AndroidRuntime(528):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 19:50:19.556: E/AndroidRuntime(528):  at android.os.Looper.loop(Looper.java:123)
09-27 19:50:19.556: E/AndroidRuntime(528):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-27 19:50:19.556: E/AndroidRuntime(528):  at java.lang.reflect.Method.invokeNative(Native Method)
Cracked
  • 93
  • 6
  • 2
    "but it doesn't work" what do you mean by that? do you get any error? – Emmanuel Sep 27 '13 at 18:57
  • Please add more detail to your question so people can answer it. Is the application crashing? Then post a crash log. Is the value not coming in correctly? Then post what the value you receive in the second intent is. Currently it's very difficult to try to figure out what you're asking. – Kasra Rahjerdi Sep 27 '13 at 19:15
  • http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android can be helpful –  Sep 27 '13 at 19:29
  • Thank you justauser it is working. – Cracked Sep 28 '13 at 16:03

1 Answers1

0
 Intent i = new Intent(this, ActivityTwo.class);
  i.putExtra("Value1", 1);
  startActivity(i);

and in other activity after oncreate()

Bundle extras = getIntent().getExtras();
int value1 = extras.getint("Value1",0);

see this detailed tutorial on Android Intents

Hamad
  • 5,096
  • 13
  • 37
  • 65
  • 2
    Why is this substantially different to what the OP is doing and why would it fix the problem? The code posted looks OK to me but without the logcat or a description of the problem, we can't be sure. As is often the case, I suspect that the problematic code has not been shown. – Simon Sep 27 '13 at 19:10
  • Good, Also useful for me Thanks – Engr Waseem Arain Dec 30 '13 at 10:25