0

I have two apps on separate devices: Rider and Driver. In the Rider App, the rider requests a ride. When they press "Request" the 2nd app, Driver open up the Call Activity for the driver to select either "Accept" or "Deny". If the driver selects "Accept", I need to call a method in a different Activity in the Driver app.

So basically, when the CallActivity opens up and the driver is selecting "Accept", I need to call recordToDB() method from another activity in the Driver app called "TrackingActivity".

How can I do this without using an intent. Why? Because the "TrackingActivity" is not used until after the driver "Accepts" the ride, but I need to call this method before that happens for my FUNCTIONS to work.

halfer
  • 19,824
  • 17
  • 99
  • 186
LizG
  • 2,246
  • 1
  • 23
  • 38
  • You can't do that. You need to rework your logic (maybe use Fragments). – TheWanderer Sep 18 '18 at 19:49
  • 2
    Why does the `recordToDB()` method need to be in an activity? Sounds like it should be in some utility class that communicates with the db independent of any activity. – Ted Hopp Sep 18 '18 at 19:50
  • It actually adds a HISTORY child to firebase with all the details of the ride requested by the rider like driver, rider, distance and price. In my "TrackingActivity" it has the method recordToDB() with the variables and values – LizG Sep 18 '18 at 19:54
  • I have created a function but keeps giving me an error: TypeError: Cannot read property 'child' of undefined at exports.newRequest.functions.database.ref.onCreate.event (/user_code/index.js:17:32) -> 17:32 = .child('price').val(); -> basically from what I can see is that it doesn't see 'price' which tells me the where I execute the method 'recordToDB' is not being executed before the function is. So I need to execute it before the function is executed which is when the driver selects 'Accept' – LizG Sep 18 '18 at 19:59
  • @LizG You should try this: https://stackoverflow.com/questions/47766894/calling-a-method-from-another-class-is-causing-app-to-crash/47772559#47772559 for this you must ensure that Activity A is called before you access method from Activity B. This will help you. – Bhoomika Patel Sep 19 '18 at 05:42
  • @TedHopp I took your advice and created a Utility class :-) – LizG Sep 19 '18 at 23:41

1 Answers1

0

Thanks for your responses.

@TedHopp I took your advice and created a Utility class and that works.

LizG
  • 2,246
  • 1
  • 23
  • 38