1

I've read android.app.Application cannot be cast to android.app.Activity but I didn't solve my problem. I tried to write in code

totalebevuto = (TextView) this.findViewById(R.id.totalebevuto);

as suggested in the post but I get an error.

    public class MyReceiver2 extends BroadcastReceiver {

    WordListOpenHelper mDB;
    WordListAdapter mAdapter;

    TextView totalebevuto;

    @Override
    public void onReceive(Context context, Intent intent) {

        mDB = new WordListOpenHelper(context);
        // AGGIUNGERE LA DATA AL DATABASE
        totalebevuto = (TextView) ((Activity)context).findViewById(R.id.totalebevuto);
        mDB.insert_daily(Integer.parseInt(totalebevuto.getText().toString()));

        mDB.clear();

        mAdapter = new WordListAdapter(context, mDB);
        mAdapter.notifyDataSetChanged();

        Toast.makeText(context, "OnReceive2", Toast.LENGTH_LONG).show();

    }

}

1 Answers1

0

I think my whole approach to getting value from the MainActivity was wrong. I saved the value I need in SharedPreferences and then retrieved it in the receiver.