I have the following android code snippet
public class Alarm extends BroadcastReceiver
{
public void makeQuery(String symbol) {
RequestQueue queue = Volley.newRequestQueue(Alarm.this);
....
and I am trying to call makeQuery
from my main activity. However, during compilation, I get the following error:
actual argument Alarm cannot be converted to Context by method invocation conversion
I understand that the current object cannot be converted into a context
, which Volley
obviously needs. Is this a property of BroadcastReceiver
? Can the this
-variable only be converted into a context
for special classes? Should I move this function makeQuery
into a different class?
I am preliminary interested in an explanation rather than a solution!
In Addition: The current setup is for testing purposes only. The method later is called from within the Alarm
class itself! Then there is no Main Activity! I need a solution to make it work then!
MainActivity.java
:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Alarm alarm = new Alarm();
alarm.makeQuery("Test");