This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 ?




 
Master Rancher
Posts: 3656
34
  • Mark post as helpful
  • send pies
  • 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.
 
That is a really big piece of pie for such a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!