views:

51

answers:

2

i want to call a new activity from within an inner class which is defined in d class which extends Activity.... the piece of written in one of the methods of that Inner class is::

Intent intent = new Intent(this, Test2.class); startActivity(intent);

Test2 is placed inside the same package as my main clas is placed and eclipse is showing me d error "The constructor Intent(test.MyTimer, Class) is undefined".......

what is the solution??

+1  A: 

I'd pass the parent to the MyTimer class in the constructor then you can pass that to the Intent. The intent requires a class that derives from Context.

So your MyTimer could look like

public class MyActivity extends Activity
{
    private void StartTimer()
    {
        MyTimer timer = new MyTimer(this);
        timer.startIntent();
    }

    private class MyTimer
    {
        private Activity _context;
        public MyTimer(Activity c)
        {
            _context = c;
        } 
        public void startIntent()
        {
          Intent i = new Intent(_context, MyActivity.class);
          _context.startActivity(i);
        }
    }
}

Hope that helps.

Rob Stevenson-Leggett
ya it helpd... thnks....my purpose was smthng but got d concept!!
poojan9118
+2  A: 

just use MyActivity.this

Intent i = new Intent(MyActivity.this, MyActivity.class);
Pentium10
ya got it...........
poojan9118
Important on SO, you have to mark accepted answers by using the tick on the left of the posted answer, below the voting. This will increase your rate.
Pentium10
wat is rate????
poojan9118
You got it pal. Keep doing the good job. The rate is the number in bold next to your name.
Pentium10
wat does dat rate signify??
poojan9118
http://stackoverflow.com/faq
Pentium10
thnx mate...i have 1 more doubt wic i hav posted as question..chck out n give me approriate solution.....thnking u in advance
poojan9118
This is actually a better answer than mine..
Rob Stevenson-Leggett