Reputation: 177
I am new on android und I try to transfer data between two Activities. Eclipse tell me that the line:
Intent i = new Intent(this, PostDataActivity.class);
Constructor Intent is undefined. What can I do?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnShowLocation = (Button) findViewById(R.id.ansehen);
// show location button click event
btnShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// create class object
gps = new GpsData(StartActivity.this);
// check if GPS enabled
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
String mlat = String.valueOf(latitude);
// \n is for new line
Intent i = new Intent(this, PostDataActivity.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
Upvotes: 1
Views: 1925
Reputation: 347
You are trying to initialize your Intent from inside an OnClickListener
. Hence, the this
parameter you are passing to your constructor refers to the listener, and not your Activity.
To fix the problem use :
Intent i = new Intent(YourActivityName.this, PostDataActivity.class);
Upvotes: 3
Reputation: 144
use
Intent i = new Intent(YourActivityName.this, PostDataActivity.class);
Upvotes: 2