• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling a function directly vs calling a function from a class in android studios ?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on two Android studio project.
In both the projects I have called the function **get_LTE_Rsrp()**:



In the first project it is called in the following manner**


onCreate{


// some code

telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
           
final PhoneStateListener mListener = new PhoneStateListener() {

@Override

public void onSignalStrengthsChanged(SignalStrength sStrength) {

signalStrength = sStrength;

mRSRP = get_LTE_Rsrp();

//display mRSRP in a textview

}

Now, in the second project i have created a class named CellularSignalInfo and made get_LTE_Rsrp() as one of its methods.


onCreate{

// some code



telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
           
final PhoneStateListener mListener = new PhoneStateListener() {

@Override

public void onSignalStrengthsChanged(SignalStrength sStrength) {

signalStrength = sStrength;

mRSRP = cellularSignalInfo.get_LTE_Rsrp();

//display mRSRP in a textview

}


Now,

nt LteRsrpStrength = (Integer) mthd.invoke(signalStrength, new Object[]{});
                           return LteRsrpStrength;**

this particular line of code works in the first project(and a corresponding value  say -111 dBm is returned)
but in the second case only the default value is returned. I have tried adding logs inside the for, if, catch, which shows the code do get executed upto that point, but the particular line of code is not executed.

What could be the reason behind this problem ?




 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try debugging the code with some print statements.
Print out the length of the methods array and inside the for loop print the value returned by mthd.getName() so you can see what the code is doing when executed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic