execute other app method from reflection
<p>I have one app A, and <strong>installed it to device</strong>.</p>

<pre><code>public class A1 extends Activity {
    void onCreate() ...
    void onResume() ...
    void showToast() {
        Toast.makeText(this, "showA1", Toast.LENGTH_SHORT).show();
    }
}
</code></pre>

<p><strong>And I wrote another app B, want to execute A1.showToast()</strong>, but encounter NullPointerException at A1.showToast().</p>

<pre><code>@SuppressWarnings("unchecked")
@Override
public void onClick(View v) {
    String packagePath = "A";
    String classPath = "A.A1";

    try {
        String apkName = getPackageManager().getApplicationInfo(
                packagePath, 0).sourceDir;
        PathClassLoader pathClassLoader = new PathClassLoader(apkName,
                ClassLoader.getSystemClassLoader());
        Class&lt;Activity&gt; handler = (Class&lt;Activity&gt;) Class.forName(
                classPath, true, pathClassLoader);
        Method[] mm = handler.getDeclaredMethods();

        for (Method m : mm) {
            Log.d("Method", m.getName());
        }

        Method method = handler.getDeclaredMethod("showToast",
                (Class[]) null);

        method.setAccessible(true);
        method.invoke(handler.newInstance(), (Object[]) null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>

<p>I know that is A1 is not initialize, so "this" is null. Someone can help me about the problem?</p>
