I've 2 layouts: MainActivity.xml, MenuActivity.xml. I want to load the MenuActivity from AsyncTask of the 1-st. Here's the UPDATED code:
class InternetCheck extends AsyncTask<Activity, Void, Boolean> {
public Activity act=new Activity();
protected Boolean doInBackground(Activity... activities) {
boolean status=false;
act=activities[0];
String rurl=act.getString(R.string.url_test);
try
{
URL url = new URL(rurl);
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1000 * 20); // mTimeout is in seconds
urlc.connect();
if (urlc.getResponseCode() == 200) {
status=true;
}
}
catch (MalformedURLException e1) {
status=false;
}
catch (IOException e) {
status=false;
}
return status;
}
protected void onPostExecute(Boolean result) {
if (result==false) {
MainActivity mActivity = (MainActivity) act;
mActivity.ShowNoConnectionButton();
}
else
{
Intent intent = new Intent(act, MenuActivity.class);
act.startActivity(intent);
//setContentView(R.layout.menu_activity);
};
}
}
If result is false we show button from UI class, and if it's true, we must load the second activity. For startActivity(intent) I get error: the method is undefined for type InternetCheck. Also is it all right with Intent parameters and calling UI method ShowNoConnectionButton from AsyncTask? It's rather difficult to understand what we must put in Intent parameters and how to get these.
BUT IT STOPS THE APP WITH ERROR.
The second screen class:
public class MenuActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_activity);
}
}