Android performance testing using "android.test.PerformanceTestCase" interface - android

I am trying to test performance of an android application using "android.test.PerformanceTestCase" interface , can anyone tell me how to make use of it...
I know i can use Traceview tool to test performance but i want learn to use "android.test.PerformanceTestCase" interface provided by android.
If i get any example code it will be very much helpful

Download the Android source code and look in frameworks/base/tests/AndroidTests/src/com/android/unit_tests. You'll find a lot of PerformanceTestCase examples.

I cloned the android source looking for the files suggested by Mirko's answer. The repository is very large and took me a while to clone. I searched it for all instances of PerformanceTestCase and found the following files which implement it:
/base/graphics/tests/graphicstests/src/android/graphics
/GraphicsPerformanceTests.java: implements PerformanceTestCase {
/base/test-runner/src/android/test
/TestRunner.java:public class TestRunner implements PerformanceTestCase.Intermediates
/base/core/tests/coretests/src/android/app/activity
/ActivityTestsBase.java: implements PerformanceTestCase, LaunchpadActivity.CallingTest {
/base/core/tests/coretests/src/android/util
/LogTest.java: public static class PerformanceTest extends TestCase implements PerformanceTestCase {
/base/core/tests/coretests/src/android/database
/CursorWindowTest.java:public class CursorWindowTest extends TestCase implements PerformanceTestCase {
/DatabasePerformanceTests.java: public static class ContactReadingTest1 implements TestCase, PerformanceTestCase {
/DatabaseStatementTest.java:public class DatabaseStatementTest extends AndroidTestCase implements PerformanceTestCase {
/DatabaseGeneralTest.java:public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceTestCase {
/NewDatabasePerformanceTests.java: implements PerformanceTestCase {
/DatabaseCursorTest.java:public class DatabaseCursorTest extends AndroidTestCase implements PerformanceTestCase {
/base/core/tests/coretests/src/android/view
/CreateViewTest.java:public class CreateViewTest extends AndroidTestCase implements PerformanceTestCase {
/InflateTest.java:public class InflateTest extends AndroidTestCase implements PerformanceTestCase {
Note that incase some of these change or are moved in the future, the commit hash I searched today was ce7dba6bdf2345f39ad8f39b8a4c1bac9bcd35ea

Related

Is it possible to write into an external library on android studio

I want to add a function into my firebase-messaging librady.The file is not writable.Is it possible somehow to write in it?
No, you can't do that. If you want to add a method to FirebaseMessagingService, make an abstract class that extends FirebaseMessagingService and extend that class in your implementations.
public abstract class BaseMessagingService extends FirebaseMessagingService {
public void yourMethod() {
}
}
public class YourActualMessagingService extends BaseMessagingService {
//...
}

Makes it sense to create an object of a class which extends Service?

Does it make sense to create an object of a class which extends Service?
I mean the following:
MainActivity.java:
public class MainActivity extends Activity{
#Override
public void onCreate(...){
MyService service = new MyService(...);
...
}
...
}
Service.java:
public class MyService extends Service{
public MyService(...){
...
}
...
}
I think it does not make sense, because e.g. in my opinion it is not possible to unregister the service. The reason: the service is never started by startService(...).
Does anyone has some hints for me? Thank you!
Although you can create an object of a class that extends Service but it doesn't make any programmatic sense. The fundamental reason to create an object is to use functionalities that class offer. In android paradigm, you would rather bind to a service to use its functionalities.

how does implement multiple types asynctaskloader

I want to use two type asynctaskloader in one FragmentActivity.
class MyLoader1 extends AsyncTaskLoader<String>{}
class MyLoader2 extends AsyncTaskLoader<Integer>{}
I write as follows. but it compile error.
public class MyActivity extends FragmentActivity
implements LoaderCallbacks<String>, LoaderCallbacks<Integer>{}
Please show me answer with easy sample code.
Thanks so much.
As hjpotter92 mentions, this is how Java handles generics. In this case, I would just suggest using anonymous classes as indicated in hjpotter92's link.
public class MyActivity extends FragmentActivity {
private LoaderCallbacks<String> mLoaderCallbackString = new LoaderCallbacks<String>() {
...
};
private LoaderCallbacks<Integer> mLoaderCallbackInteger = new LoaderCallbacks<Integer>() {
...
};
}
Then for each loader, you just pass the correct LoaderCallbacks object

Use different (AsyncTask) Loaders in one Activity

I want to use different AsyncTaskLoaders (different in their return type) in my Activity, what's the best way to implement the callback methods?
This won't work:
public class MyActivity extends Activity implements
LoaderManager.LoaderCallbacks<MyPojo>,
LoaderManager.LoaderCallbacks<MyOtherPojo>
Eclipse says
The interface LoaderCallbacks cannot be implemented more than once with different arguments
So what do I do? My idea is to make the Activity
implements LoaderManager.LoaderCallbacks<Object>
then check in the callback methods what type of object it is but that doesn't seem too elegant. Is there a better way?
What about creating an inner class for each callback?
public class MyClass extends Activity {
private class Callback1 implements LoaderManager.LoaderCallbacks<MyPojo> {
...
}
private class Callback2 implements LoaderManager.LoaderCallbacks<MyOtherPojo> {
...
}
}

Android generic ArrayAdapter

I have multiple classes, which all extend some BasicDataModel:
public class NewsItem extends BasicDataModel
public class PhotosItem extends BasicDataModel
etc. So I need to make ArrayAdapters for all of them, and I wonder if it is possible to make some generic ArrayAdapter to fit all my objects. So far I tried to make
public class MyAdapter extends ArrayAdapter<BasicDataModel>
but as long as I pass ArrayList, for example, this doesn't work.
Thanks in advance
Try
public class MyAdapter<T extends BasicDataModel> extends ArrayAdapter<T>
and use
MyAdapter<NewsItem> news;
I tried Nikita Beloglazov suggestion:
public class MyAdapter<T> extends ArrayAdapter<T extends BasicDataModel>
but found that it wouldn't compile.
Then I tried:
public class MyAdapter<T extends BasicDataModel> extends ArrayAdapter<T>
and that worked just fine :)
Try the PIArrayAdapter.
reduce your code size and headache of maintaining it again.
just plug and play with simple annotations
pull it #
https://github.com/peeyush18/CustomAdapter.git
or view it at
https://github.com/peeyush18/CustomAdapter

Categories

Resources