-1

I am writing a code for going to the next page after clicking a button so I have written the code that I have mentioned below i just want to confirn that it is correct as i cant check it now, I know this is silly but I need help

 package com.example.myfirstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class DetailsActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_details);
            Button btnNextScreen = (Button) findViewById(R.id.btnNextScreen);
            btnNextScreen.setOnClickListener(new View.OnClickListener() {

                public void onClick(View view) {
                    Intent nextScreen = new Intent(getApplicationContext(), JewelInfo.class);
                    // TODO Auto-generated method stub
                    startActivity(nextScreen);
                }
            });
        }
}
Shri
  • 77
  • 1
  • 1
  • 5
  • 1
    why dont you run this on emulator and check yourself? – hemantsb Sep 25 '13 at 09:27
  • use `DetailsActivity.this` instead of `getApplicationContext()`, and declare your `JewelInfo` activity on the manifest file : ``. Here is a tutorial about how to switch between activities and pass data between them : http://www.android-ios-tutorials.com/android/how-to-switch-between-different-activities-in-android – Houcine Sep 25 '13 at 09:53

4 Answers4

0

Assuming that your JewelInfo extends from an Activty it looks fine.

S.A.Norton Stanley
  • 1,833
  • 3
  • 23
  • 37
  • yes it extends Activity but I dont know how to declare it in manifest – Shri Sep 25 '13 at 09:34
  • what should i do if i want to forward the browsed image to the next page i.e. next activity... how can I do that – Shri Sep 25 '13 at 09:45
  • here is a tutorial about how to switch between activities and pass data between them : http://www.android-ios-tutorials.com/android/how-to-switch-between-different-activities-in-android – Houcine Sep 25 '13 at 09:51
0

I think you should use Intent nextScreen = new Intent(DetailsActivity.this, JewelInfo.class); instead of getApplicationContext()

rdbmsa
  • 296
  • 3
  • 14
  • yeah thanks, but what id getApplicationContext will do?? and what difference will it make?? – Shri Sep 25 '13 at 09:46
  • There are two different Context objects. getApplicatoinContext() - gives context of application, and if you want to use them, you should start new activity with Intent.FLAG_ACTIVITY_NEW_TASK. But if you start new activity in the same task, you should use activity context DetailsActivity.this – rdbmsa Sep 25 '13 at 14:49
  • You can find some explanations about contexts there [link](http://stackoverflow.com/questions/10347184/difference-and-when-to-use-getapplication-getapplicationcontext-getbasecon) – rdbmsa Sep 25 '13 at 14:51
0

The correctness of code is never checked just by looking at a bit of code. Syntactically, it seems to not contain an error. Semantically, how should we know? You need to define what you want to do, how you want it to look, etc. Basically, what are the requirements?

We can then validate the code against the requirements but not assess the correctness as that is only discerned by executing the code and evaluating the result of the execution on the device it is executed against the requirements.

Eric Tobias
  • 3,225
  • 4
  • 32
  • 50
-1

use DetailsActivity.this instead of getApplicationContext(), and declare your JewelInfo activity on the manifest file : <activity android:name=".JewelInfo" />.Check this tutorial about how to switch between activities and pass data between them

Houcine
  • 24,001
  • 13
  • 56
  • 83
  • persons who dowvoted should add a comment below the answer in order to understand the reason of that downvote , and correct the error in the answer :) – Houcine Sep 26 '13 at 00:56