I am new to Android development and managed to get this far reading questions and answers on StackOverflow. Thank you everyone.
I came up with a problem that I just can't figure out. I have seen similar problems posted but the answers are not clear to me. Please help me on this one.
I want to call a method on my main activity from another class. The app crashes when I try to call the method. Here is the code:
On the class file:
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
MainActivity MainActivity = new MainActivity();
MainActivity.ligaInternet();
}
}
On the mainactivity file:
protected void ligaInternet() {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
String urlText="http://www.regiprof.com/regiprof_sms.php";
String stringUrl = urlText.toString();
new DownloadWebpageTask().execute(stringUrl);
}
}
How can I call the ligaInternet()
function?