I tried to call non static method from static method but without any result ,my application works crash my code :
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAuth();
///
///
}
public static void setAuth() {
new MainActivity().d();
}
public void d()
{
Toast.makeText(getApplicationContext(), "fff",Toast.LENGTH_SHORT).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Is it permissible to call non static method from static method in android?? and how???
new MainActivity()for an Activity. I think your main task is to show Toast. So pass a Context object as param to setAuth() and show your toast using that context object.