Android call Intent from Inner class

I want to call a new action from an inner class, which is defined in class d, which extends Activity .... a piece of code written in one of the methods of this Inner class:

Purpose of Intent = New Intent (this, Test2.class); startActivity (intent);

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

What is the solution?

+5
source share
2 answers

MyTimer , . , .

, MyTimer

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);
        }
    }
}

, .

+4

MyActivity.this :

Intent i = new Intent(MyActivity.this, MyActivity.class);
+13

All Articles