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 7841297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:04:16+00:00 2026-06-02T16:04:16+00:00

What i am trying to do is to dispatch the motion event to currently

  • 0

What i am trying to do is to dispatch the motion event to currently running activity . I have got the ComponentName of the current activity from this code

ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

// get the info from the currently running task
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);

Log.d("current task :", "CURRENT Activity ::" + 
            taskInfo.get(0).topActivity.getClassName());

ComponentName componentInfo = taskInfo.get(0).topActivity;

Now that I have the component name, I want to dispatch the event

dispatchTouchEvent(MotionEvent ev)

that is in the Activity class, and to do this I need an instance of the current activity. I am stuck at component name. How can I get the Activity instance so that I can dispatch the event?

  • 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-02T16:04:16+00:00Added an answer on June 2, 2026 at 4:04 pm

    Wow, there are so many things wrong with this question it is hard to know where to start! Let’s take them in order:

    What i am trying to do is to dispatch the motion event to currently running activity

    The current foreground activity will get motion events, unless it should not. The only way I can imagine this making any sense is that your service has put a system window up that is going on top of all the apps… and in that case, I would urge you to not do this and just let your foreground activity handle the event.

    I have got the ComponentName of the current activity from this code

    ActivityManager.getRunningTasks() is not for normal application development. This is intended for things like task managers and such. You should never write core program logic that has dependencies on the information returned by this function. That is begging for trouble, and in fact I can guarantee such code will break at some point. (What happens when multiple applications can be running in the front at the same time?)

    I want to dispatch the event

    You really, really should not be ripping motion events out of one window and stuffing them in to another. Various dispatch state will not be set up correctly, state in the event will not be consistent (the event was set up with an origin and such for the original window, not the new one you are stuffing it in), etc. This is another great way to make a flaky application that has a good chance of breaking in the future, if you can even kludge it to make it work at all today.

    I am stuck at component name. How can I get the Activity instance so that I can dispatch the event?

    Indeed, all you have is a component name. That has nothing to do with active instances. There is no magic way to turn this into an actual instance. It would be wrong to supply one, because this can easily be ambiguous (if there were two instances of that class instantiated).

    I think you need to back-up to the start and look at what you are actually trying to accomplish, to get help on what a reasonable way of approaching it is. The path you have gotten yourself down is at this point pretty terminal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about the event dispatch. I am trying to write the
I am trying to dispatch a custom event from one flex module to another.
Eventdispatching here we are again... I'm trying to dispatch a custom event from an
I am trying to get some code working from an example I came across.
In a FLEX app, I am trying to re-dispatch a custom event. I.e. component1
Basically I'm trying to dispatch a custom made mouse click event to a text
I am trying to GET a response from an API, using scala and dispatch.
I'm trying to dispatch MouseEvent for HTML component in an AIR application. This way
I'm trying to create custom view that draws image downloaded from Url. The code
I am trying to dispatch (inject) a GTK keyboard event to some window, in

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.