0

I want to pass the "infor" string to the class entrar_antes_camera how can i do it? I tried using intent but i cant put the ManagingRequests class inside the intent along the entrar_antes_camera class

public class ManagingRequests
{
    private void makeMaps()
    {
        this.mapped.put
        (
            "homeActions", //\MakeMaps.homeActions
            new ManagingRequests.Callback()
            {
                public void callback(String callback, String[] proposed_data) 
                    throws Exception
                {
                    JSONObject jo = comply(proposed_data).getJSONObject(0);
                    switch( jo.getString("action") )
                    {
                        case "Notification": {
                            ManagingRequests.this.db.updateAlertas(jo.getString("codigo"));
                        }
                        break;
                        case "Register": {
                            info = entry_point.getSharedPreferences("info", MODE_PRIVATE);
                            if (info.contains("cc")) {
                                String infor = info.getString("cc", "");
                                Log.i("CC INFO", infor);
                                Intent intent = new Intent (ManagingRequests.this, entrar_antes_camera.class)
                            }else
                            ManagingRequests.this.initiateRegister();
                        }
                        break;
                        case "Mirror":
                            ManagingRequests.this.showSystemTab( Asset.TIMESHEET_SUFFIX_URL );
                        break;
                        case "Schedule":
                            ManagingRequests.this.showSystemTab( Asset.SCHEDULE_SUFFIX_URL );
                        break;
                    }
                }
            }
        );

i want to put infor in this activity

public class entrar_antes_camera extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_entrar_antes_camera);


    }
}

1 Answers1

0

The below line is causing the problem

Intent intent = new Intent (ManagingRequests.this, entrar_antes_camera.class);

AS you are putting ManagingRequests.this as the first argument of the Intent constructor, which is not right as ManagingRequests is not considered a context as it doesn't extend from AppCompatActivity. The Intent constructor first argument expects a context instead.

So to solve this, In order to launch entrar_antes_camera.class activity, you need to add the current activity context (which is not mentioned in your question) as the first argument to the Intent Constructor instead of ManagingRequests.this.

Zain
  • 37,492
  • 7
  • 60
  • 84
  • Understood, but how can i do it? Because i tried doing like this `Intent intent = new Intent(infor, entrar_antes_camera.class);` and it didnt work – Lucca Germano Mar 18 '20 at 20:37
  • @LuccaGermano so in order to launch an activity (say Activity B), you have to move from some activity which is the current activity displayed on the screen (say Activity A) to that activity; the first argument of the `Intent` constructor should be the context of Activity A, and the second argument should be ActivityB.class you got it? – Zain Mar 18 '20 at 20:40
  • @LuccaGermano for more info please check [this thread](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) out – Zain Mar 18 '20 at 20:48