thequestionasker
thequestionasker

Reputation: 11

Android: Return the radius of a circle?

I created a custom view class that allows the user to draw a circle on the canvas. The circle is drawn with drawCircle and the radius is measured by location of pointers. Now in the activity that displays the circle, I want to send the radius of the circle to another activity and then do some calculations on it.

Is there an easy way to do this?

For example, the user will draw a circle and then click the Done button. The Done button calls this method that will move the application to the next activity:

public void goToNext(View view)
{
    Intent intent = new Intent(this, output.class);


}

But I don't know how to pass the radius of the circle to the output class

Upvotes: 1

Views: 916

Answers (2)

Quanturium
Quanturium

Reputation: 5696

You can sent extra data with your intent to the output activity.

public void goToNext(View view)
{ 
    Intent intent = new Intent(this, output.class);
    intent.putExtra("radius", yourView.getRadius());
    startActivity(intent);
} 

Then in your output.class activity you can access the data with

getIntent().getIntExtra("radius", -1); // -1 is the default value

More informations: http://developer.android.com/guide/components/activities.html#StartingAnActivity

Upvotes: 1

itayrabin
itayrabin

Reputation: 426

use Intent.putExtra to put any data you want to transfer between activities. you need to have a keyword that doesn't change so use a final String for it. in your case it would be something along the lines of

public void goToNext(View view)
{
    Intent intent = new Intent(this, output.class);
    intent.putExtra(KEY_RADIUS, customView.getRadius);
    startActivity(intent);

}

Upvotes: 3

Related Questions