Tenho as duas classes abaixo:
DataLoad.java
public class DataLoad extends Activity {
SQLiteDatabase mDatabase;
Session session;
public static String jsonString = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_load_activity);
// OBJECTS
CRUD crud = new CRUD(getApplicationContext());
session = new Session(getApplicationContext());
crud.destroy();
if(!Functions.DatabaseExists(getApplicationContext().getDatabasePath(Config.DATABASE_NAME).toString())){
try {
crud.open();
getAppData();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void getAppData(){
Webservices webservice = new Webservices(getApplicationContext());
webservice.execute();
}
public void Builder(){
session.insert("json_content", jsonString);
Intent intent = new Intent(DataLoad.this, Login.class);
startActivity(intent);
}
}
Webservices.java
public class Webservices extends AsyncTask<String,String,String> {
Context mContext;
ProgressDialog progressDialog;
public Webservices(Context context){
mContext = context;
}
@Override
protected String doInBackground(String... string) {
String RETRIEVED_CONTENT = "";
InputStream inputStream;
try {
// New HTTP Object
HttpClient httpclient = new DefaultHttpClient();
// New POST Object
HttpPost httppost = new HttpPost(Config.DOMAIN+Config.WEBSERVICE_PATH+Config.DATA_FILE);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line;
while((line = reader.readLine()) != null){
sb.append(line).append("\n");
}
RETRIEVED_CONTENT = sb.toString();
} catch (Exception e) {
Log.e("HTTP", "Error in http connection " + e.toString());
}
DataLoad.jsonString = RETRIEVED_CONTENT;
return RETRIEVED_CONTENT;
}
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(mContext, "Por favor aguarde...", "Validando dados de login.", true);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
DataLoad dataLoad = new DataLoad(mContext);
dataLoad.Builder();
}
}
Preciso de conseguir executar a função Builder
da classe DataLoad dentro do método onPostExecute
mas estou a receber o seguinte erro:
7247-7247/pt.project01 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pt.project01/pt.project01.ui.activities.DataLoad}: java.lang.InstantiationException: can't instantiate class pt.cartuxa_pro_gold.ui.activities.DataLoad; no empty constructor
Como posso manipular o método onPostExecute
para que depois de executado eu consegui chamar outras funções dentro da classe que o ativou?
Activity
(DataLoad). Para poder chamar métodos da classeDataLoad
no final da execução doonPostExecute
você precisa implementar o design patternListener
(Observer).