Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Activities are started with <a href="http://developer.android.com/reference/android/content/Intent.html" rel="nofollow noreferrer">Intents</a>. Please read the <a href="http://developer.android.com/guide/topics/fundamentals.html" rel="nofollow noreferrer">Android Application Fundamentals</a> first and try the Hello World app :)</p> <p>I understood that you will use your separate Tester class at all cost ;) so I'm trying to adapt and help you out there. </p> <p>First of all, <strong>don't</strong> let your class inherit from Activity. This won't help you, cause this calls will probably not have any valid context. Activity somehow implements the <strong>template pattern</strong>, providing you key method like <code>onCreate(...)</code>, <code>onPause(...)</code> etc and is instantiated by the Android OS.</p> <p>If you still want to use the class, you have to pass in the context. Probably you're aiming for some MVC/MVP pattern structure, anyway.</p> <pre><code>public class Tester { private Context context; public Tester(Context context){ this.context = context; } public void test () { final Intent myIntent = new Intent(context, NewActivity.class); //guess this comes from somewhere, hope through a findViewById method thebutton.setOnClickListener( new OnClickListener() { public void onClick(View v) { context.startActivity(myIntent); } } )}; } } </code></pre> <p>This would be a proposed solution from my side. A problem I still see here is on <strong>how you retrieve the button</strong> in that <code>test()</code> method. In order to have that work properly you have to retrieve it from some View class (with <code>view.findViewByid(R.id.myButton)</code>) or to create it dynamically and associate it with the view during the <code>onCreate(...)</code> of your Activity (probably using an Inflater).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload