Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:46:18+00:00 2026-06-09T16:46:18+00:00

I am trying to call an activity from a non activity class but I

  • 0

I am trying to call an activity from a non activity class but I m not able to accomplish this task .My goal is to call a new activity from info window , when the image in the info window is clicked . How can I call activity from non activity class ? Any help is appreciated .Thank you.

package com.icons.draw.view;

 import java.util.Iterator; 
  import java.util.List;

 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Point;
 import android.graphics.RectF;
 import android.graphics.Paint.Style;
 import android.os.Handler;
 import android.util.Log;
 import android.widget.Toast;

 import com.google.android.maps.GeoPoint;
 import com.google.android.maps.MapView;
 import com.google.android.maps.Overlay;

 import com.icons.draw.R;





 public class MapLocationOverlay  extends Overlay {

/**
 * Stored as global instances as one time initialization is enough
 */
private Bitmap mBubbleIcon, mShadowIcon;

private LocationViewers mLocationViewers;

private Paint   mInnerPaint, mBorderPaint, mTextPaint;

private Bitmap iconForMapKit,iconForMapKitRollOver;

private Handler mHandler=new Handler();

private boolean flag=false;

 private int [] start,end ; 

 private boolean checkAnimationEnded; 


private Point arrowPointCoordinates = new Point(); 

/**
 * It is used to track the visibility of information window and clicked location is known location or not 
 * of the currently selected Map Location
 */
private MapLocation mSelectedMapLocation;  
private void fillYCoordinateArrayForPinDropAnimation(LocationViewers  mapLocationViewer) 
{  
    List<MapLocation> mList = mapLocationViewer.getMapLocations(); 
    int size = mList.size(); 
    start = new int[size]; 
    end = new int[size]; 
} 
private boolean checkTwoArrayForEquality(int [] a , int [] b) 
{ 
  boolean result = true ; 

  for(int i = 0 ; i< a.length ; i++) 
  { 
      if(a[i] < b[i]){ result = false; break; } 
  }  
  Log.v("Coor", "Coor Resut = "+ result); 
  return result; 
} 



public MapLocationOverlay(LocationViewers mLocationViewers) {


    this.mLocationViewers = mLocationViewers;

    mBubbleIcon = BitmapFactory.decodeResource(mLocationViewers.getResources(),R.drawable.bubble);
    mShadowIcon = BitmapFactory.decodeResource(mLocationViewers.getResources(),R.drawable.shadow);
    iconForMapKit = BitmapFactory.decodeResource(mLocationViewers.getResources(),R.drawable.arrowformapkit); 
    iconForMapKitRollOver = BitmapFactory.decodeResource(mLocationViewers.getResources(),R.drawable.arrowformapkit_rollover); 
    fillYCoordinateArrayForPinDropAnimation(mLocationViewers); 

}



@Override
public boolean onTap(GeoPoint p, final MapView mapView)  {

    /**
     * Track the popup display
     */
    boolean isRemovePriorPopup = mSelectedMapLocation != null;  

    /**
     * Test whether a new popup should display
     */
      if(moreArrowTappedEvent(mapView,p) && isRemovePriorPopup) 
        { 
          // Toast.makeText(this.mLocationViewers.getContext(), "I am hit", Toast.LENGTH_LONG).show(); 

                         /*  Intent intent=new Intent();
          intent.setClass(this.mLocationViewers.getContext(), NewActivity.class); 
          startActivity(intent);*/





            flag = true; 
            mapView.invalidate(); 

            mHandler.postDelayed(new Runnable() { 

                public void run() { 
                    // TODO Auto-generated method stub 
                    flag = false; 
                    mapView.invalidate(); 
                } 
            },200L); 



        }
            else{
    mSelectedMapLocation = getHitMapLocation(mapView,p);
    if ( isRemovePriorPopup || mSelectedMapLocation != null) {
        mapView.invalidate();
    }   }   

    /**
     *   Return true if we handled this onTap()
     */
    return mSelectedMapLocation != null;
}

private boolean moreArrowTappedEvent(MapView mapView, GeoPoint tapPoint) {
     boolean result = false; 

        RectF hitTestRecr = new RectF(); 
        Point screenCoords = new Point(); 
        // Create a 'hit' testing Rectangle w/size and coordinates of our icon 
        // Set the 'hit' testing Rectangle with the size and coordinates of our on screen icon 
        hitTestRecr.set(arrowPointCoordinates.x,arrowPointCoordinates.y,arrowPointCoordinates.x+iconForMapKit.getWidth(),arrowPointCoordinates.y+iconForMapKit.getHeight()); 


        //  Finally test for a match between our 'hit' Rectangle and the location clicked by the user 
        mapView.getProjection().toPixels(tapPoint, screenCoords); 
        if (hitTestRecr.contains(screenCoords.x,screenCoords.y)) { 
            result = true; 
        } 
        return result;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {

    drawMapLocations(canvas, mapView, shadow);
    drawInfoWindow(canvas, mapView, shadow);

 if(!checkTwoArrayForEquality(start, end)) 
 { 
     for(int i = 0; i<start.length ; i++) 
     { 
         if(start[i] < end[i] ) start[i]+=3; 
     } 
     mapView.invalidate(); 
 } 
 else 
 { 

     checkAnimationEnded = true; 
 }    


}

/**
 * Test whether an information balloon should be displayed or a prior balloon hidden.
 */
private MapLocation getHitMapLocation(MapView   mapView, GeoPoint   tapPoint) {

      MapLocation hitMapLocation = null; 

        RectF hitTestRecr = new RectF(); 
        Point screenCoords = new Point(); 
        Iterator<MapLocation> iterator = mLocationViewers.getMapLocations().iterator(); 
        while(iterator.hasNext()) { 
            MapLocation testLocation = iterator.next(); 

            //  Translate the MapLocation's lat/long coordinates to screen coordinates 
            mapView.getProjection().toPixels(testLocation.getPoint(), screenCoords); 

            // Create a 'hit' testing Rectangle w/size and coordinates of our icon 
            // Set the 'hit' testing Rectangle with the size and coordinates of our on screen icon 
            hitTestRecr.set(-mBubbleIcon.getWidth()/2,-mBubbleIcon.getHeight(),mBubbleIcon.getWidth()/2,0); 
            hitTestRecr.offset(screenCoords.x,screenCoords.y); 

            //  Finally test for a match between our 'hit' Rectangle and the location clicked by the user 
            mapView.getProjection().toPixels(tapPoint, screenCoords); 
            if (hitTestRecr.contains(screenCoords.x,screenCoords.y)) { 
                hitMapLocation = testLocation; 
                break; 
            } 
        } 

        //  Lastly clear the newMouseSelection as it has now been processed 
        tapPoint = null; 

        return hitMapLocation;  

}

private void drawMapLocations(Canvas canvas, MapView    mapView, boolean shadow) {

     Iterator<MapLocation> iterator = mLocationViewers.getMapLocations().iterator(); 
        Point screenCoords = new Point(); 

        int pos = 0; // for drop pin effect  
        while(iterator.hasNext()) {     
            MapLocation location = iterator.next(); 
            mapView.getProjection().toPixels(location.getPoint(), screenCoords); 
            shadow = false ; // remove this line if want shadow to be drawn also..  

            end[pos] = screenCoords.y - mBubbleIcon.getHeight();// for drop pin effect 
            if (shadow) { 
                //  Only offset the shadow in the y-axis as the shadow is angled so the base is at x=0;  
                canvas.drawBitmap(mShadowIcon, screenCoords.x, screenCoords.y - mShadowIcon.getHeight(),null); 
            }  
            else { 
                if(checkAnimationEnded) 
                { 
                    canvas.drawBitmap(mBubbleIcon, screenCoords.x - mBubbleIcon.getWidth()/2, screenCoords.y - mBubbleIcon.getHeight(),null); 
                } 
                else 
                { 
                    canvas.drawBitmap(mBubbleIcon, screenCoords.x - mBubbleIcon.getWidth()/2, start[pos],null); // for drop pin effect 
                }    


                //canvas.drawBitmap(bubbleIcon, screenCoords.x - bubbleIcon.getWidth()/2, screenCoords.y - bubbleIcon.getHeight(),null); 
            } 

            pos++;// for drop pin effect 
        } 

}

private void drawInfoWindow(Canvas canvas, MapView  mapView, boolean shadow) {

    if ( mSelectedMapLocation != null) { 
        if ( shadow) { 
            //  Skip painting a shadow in this tutorial 
        } else { 
            //  First determine the screen coordinates of the selected MapLocation 
            Point selDestinationOffset = new Point(); 
            mapView.getProjection().toPixels(mSelectedMapLocation.getPoint(), selDestinationOffset); 

            //  Setup the info window with the right size & location 
            int INFO_WINDOW_WIDTH = 200; 
            int INFO_WINDOW_HEIGHT = 50; 
            RectF infoWindowRect = new RectF(0,0,INFO_WINDOW_WIDTH,INFO_WINDOW_HEIGHT);              
            int infoWindowOffsetX = selDestinationOffset.x-INFO_WINDOW_WIDTH/2; 
            int infoWindowOffsetY = selDestinationOffset.y-INFO_WINDOW_HEIGHT-mBubbleIcon.getHeight(); 
            infoWindowRect.offset(infoWindowOffsetX,infoWindowOffsetY); 

            //  Draw inner info window 
            canvas.drawRoundRect(infoWindowRect, 5, 5, getmInnerPaint()); 

            //  Draw border for info window 
            canvas.drawRoundRect(infoWindowRect, 5, 5, getmBorderPaint()); 

            //  Draw the MapLocation's name 
            int TEXT_OFFSET_X = 10; 
            int TEXT_OFFSET_Y = 15; 
            String name = mSelectedMapLocation.getName(); 
            if(name.length() >= 28) 
            { 
                name = name.substring(0, 26)+".."; 
            }    
            canvas.drawText(name,infoWindowOffsetX+TEXT_OFFSET_X,infoWindowOffsetY+TEXT_OFFSET_Y,getmTextPaint()); 
        //  canvas.drawText(selectedMapLocation.getPrice(),infoWindowOffsetX+TEXT_OFFSET_X,infoWindowOffsetY+TEXT_OFFSET_Y+20,getTextPaint()); 
            if(!flag) 
            { 
                canvas.drawBitmap(iconForMapKit, infoWindowOffsetX+160,infoWindowOffsetY+10, null);  
            } 
            else 
            { 
                canvas.drawBitmap(iconForMapKitRollOver, infoWindowOffsetX+160,infoWindowOffsetY+10, null); 
            }    

            arrowPointCoordinates.x = infoWindowOffsetX+160; 
            arrowPointCoordinates.y = infoWindowOffsetY+10; 
        } 
    } 
}

public Paint getmInnerPaint() {
    if ( mInnerPaint == null) {
        mInnerPaint = new Paint();
        mInnerPaint.setARGB(225, 50, 50, 50); //inner color
        mInnerPaint.setAntiAlias(true);
    }
    return mInnerPaint;
}

public Paint getmBorderPaint() {
    if ( mBorderPaint == null) {
        mBorderPaint = new Paint();
        mBorderPaint.setARGB(255, 255, 255, 255);
        mBorderPaint.setAntiAlias(true);
        mBorderPaint.setStyle(Style.STROKE);
        mBorderPaint.setStrokeWidth(2);
    }
    return mBorderPaint;
}

public Paint getmTextPaint() {
    if ( mTextPaint == null) {
        mTextPaint = new Paint();
        mTextPaint.setARGB(255, 255, 255, 255);
        mTextPaint.setAntiAlias(true);
    }
    return mTextPaint;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:46:20+00:00Added an answer on June 9, 2026 at 4:46 pm

    I see this code in your listing which is commented:

    Intent intent=new Intent();
    intent.setClass(this.mLocationViewers.getContext(), NewActivity.class); 
    startActivity(intent);
    

    Why is it commented? Basically, this is a way how you would call a new activity.

    Edit:
    I see. The startActivity() should be called by a context object, otherwise it will say the method it’s undefined.

    In your class MapLocationOverlay create a new member variable of type Context, then modify your constructor to accept a Context parameter:

    private Context mContext;
    
    public MapLocationOverlay(Context context, LocationViewers mLocationViewers){
        this.mContext = context;
       //..........
    }
    

    Then you would call the startActivity() like this:

    mContext.startActivity(intent);
    

    Obviously when you’ll instantiate the MapLocationOverlay, you’ll need to pass a context reference to it too.
    ex:

     = new MapLocationOverlay(this, mLocationViewers);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this exception while I am trying to call an activity from
I'm trying to call the Facebook authorization from my Android activity, but for some
I am Trying to call an Activity from Default activity but when trigger the
I'm trying to call a method from another class with a simple button in
I'm trying to call a function present in one class from another class by
I'm trying to start an activity from a service running in background but its
I am trying to call a static method from another activity to find a
I'm trying to call a service from a activity: When I'm running the program
I am trying to call an Activity from another instance of the activity. The
I am currently trying to call a method from a utility class that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.