Is it possible to abstract a startActivity call?

I was wondering if it's possible to abstract a startActivity call? What I'm trying to do is abstract the following:

        Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
         public void run() { 
    }, 2000); 

Where I've previously setup the intent nextIntent with the proper class and the proper extras. The idea is that I will be delaying the intent from starting for 2 seconds. The above code works fine if I call it directly from my Activity. What I'd like to do is abstract the above code so that I could call it from any activity like this:


This would start the next Activity nextIntent after a 2 second delay. However, when I try to code this I get the following error:

The method startActivity(Intent) is undefined for the type new Runnable(){}

I've looked at topics like this: Is that possible to call for startActivity() from a static method?, but that thread defines the intent in the method. I'd like to be able to take an intent that I've already setup and pass that. Is what I'm looking for possible to do? If so, what changes do I need to make? Thank you so much.


I'm a little dubious of what you're trying to achieve. Do you really have enough activities that this is useful? It sounds like you're trying to make a "pager" sort of service. So why not just do that instead?

Additionally, you probably don't really want to create your own Handler, you probably just want to post that to the GUI thread of the Activity (really!). So I'd reconsider your design.

But if you just want to disregard all of that, the answer to your immediate question is that you should pass a Context (such as a this from your Activity instance) on which you should call startActivity.

Need Your Help

how can use heroku db:push

ruby-on-rails sqlite postgresql heroku

I have a Ruby 1.9.3p194/Rails 3.2.7 application. I want to push my local database to heroku.

shared layout in mvc

i have created new empty Asp.Net mvc 4 , and add New Folder Shared in View and new file _Layout.cshtml and put this cod to that

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.