I need a thread repeating after 30 seconds that load data from web service. i want to stop and start thread onResume and onPause so that it runs when screen is active and disable it when activity paused. Restart on resume.

new Handler().postDelayed(new Runnable() {

        public void run() {

    }, 30000);

How to stop it when activity paused.

I am using retrofit 2.0.0-beta1 and okhttp2.4.0 for get the response from server in android studio.I go the java.net.SocketTimeoutException when using api url with port number like http:\test.com:3000\getcustomers.Plesae help me to solve this problem.

API Url: http://test.com:3000/hotelbooking/userLogin. when using port no with api its not working in retrofit

I've looked around but never found a straightforward answer to this question. I'm wondering what would happen if I use a pattern that requires me to pass a Context to static methods to do things on the backend. For instance:

public static Observable<CreateThing> createNewThing(String thingName, Context context) { // Passing Context in
    return RestNetworker.handleResponse(ServiceGenerator.createService(Service.class).createThing(thingName))
            .doOnNext(response -> DatabaseHelper.getInstance(context).createThing(new Thing(response.getThingId(), thingName))); // context used to get instance of DatabaseHelper

This method makes an API call and then writes the object to the database locally after a success response. However, I need to pass a Context to create the instance of the database helper. I could alternatively pass the database helper itself, but then I'd be creating the instance (rather getting it, since it's singleton) in the Activity code and I'd rather not do that either.

My question really is: If, say, a user exits the Activity while the API call is in progress, will this Context instance get GC'd and result in an NPE when the response comes back? I've done this kind of thing before and never noticed that issue, but it really seems that there should be some consequence of doing this. I know that other developers must do some things off the UI thread that require a Context, so this should be a relatively easy question to answer.

Thanks guys! Please let me know if you need any more information to provide better context. Heh.

I have a listview with a heade view added to it. In this listview I have a fast scrollbar with section indexer. But the fast scrollbar start a the top of the list right to the header.

I would like fast scrollbar start at first item below header. Is it possible?

I have Vertical Bar chart with each bar of different color. Here Each series contains One item . Such list of Series are added to XYMultipleSeriesRenderer. I am not able to Reduce Bar spacing.

 private List<XYSeriesRenderer> getXYSeriesRenderer(){
        ArrayList<XYSeriesRenderer> xySeriesRenderers = new ArrayList<>();
        Resources resources = mActivity.getResources();
        XYSeriesRenderer xySeriesRenderer;

    for(int i = 0; i<5; i++){

        xySeriesRenderer = new XYSeriesRenderer();

        switch (i){
            case 0 :{

            case 1 : {

            case 2 : {

            case 3 : {

            case 4 : {

            default: {
        SDLog.d("Adding XYSeriesRenderer to List -> sySeriesRenderer :: "+ xySeriesRenderer.toString());

    return xySeriesRenderers;

then I do this:

for (XYSeries series: ratingSeries) {
            SDLog.d("Adding XY Series to Multiple Series Dataset :: title ->"+ series.getTitle());

Actually i have created custom keyboard for my application. It's working absolutely fine on every screen all the activities, but I don't know how to set custom keyboard on alert dialog.

I am using below code to call keyboard in activities:

    UserPayAmount.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {

            customFractionalKeyboard= new CustomFractionalKeyboard(VendorPaymentActivity.this, R.id.keyboard_number, R.xml.fractional_keyboard);


            return false;

I want to create keyboard on this dialog, above buttons.

So i'm making an application, and i'm using Maps API on Android and i have these two methods

public void onGpsStatusChanged(int i) {
    Log.i("gps status mudou",111+"");

So, the first one was implemented in API level 24 and the other one deprecated, since i want this application to work in almost all devices, what i want to know is if i have to use both methods or just one of them, and if is just one what should i use? Thank you

I have created a custom keyboard app , My app is consuming high RAM around 150-200 MB,when I tried to dump memory info from

adb shell dumpsys meminfo

this is what I get even when my keyboard is not opened.

                   Views:      364         ViewRootImpl:        1
             AppContexts:        3           Activities:        0
                  Assets:        5        AssetManagers:        5
           Local Binders:       45        Proxy Binders:       32
           Parcel memory:       16         Parcel count:       64
        Death Recipients:        4      OpenSSL Sockets:        0

Views:      364 //number increases when I open and close keyboard for few times.

How to clear these views?

I tried calling


it drops the memory consumption directly to 10 MB and clear all the views but in this case , my keyboard open very slowly.

Here is lifecyle,every time when I open keyboard (when I kill process on onFinishInputview) :

 I/FA: App measurement is starting up, version: 9256
 I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
 I/FirebaseInitProvider: FirebaseApp initialization successful
 I/MultiDex: install
 I/MultiDex: VM has multidex support, MultiDex support library is disabled.
 D/SoftKeyboard: onCreate invoked! 

 D/SoftKeyboard: onInitializeInterface invoked! 
 D/SoftKeyboard: onStartInput invoked!


Which uses the Android Widget Toolbar and takes the users GPS location, at Runtime after the Splash screen and before login Activity.

I know how to add permissions to the manifest and I am using both the permissions ACCESS_FINE_LOCATION and ACCESS_COURSE_LOCATION.

By using this command i am able to get the package. output:C:\Project\Tools\sdk-repo-windows-platform-tools-2219198\platform-tools>adb shell dumpsys window windows | grep -E 'mCurrentFocus' mCurrentFocus=Window{11dc5df u0 com.android.phone/com.android.phone.CallFeaturesSetting}

From this output i am getting package as com.android.phone, but i want to access the "callFeaturesSettings" using abd command for my automation. By using this command "adb shell monkey -p com.android.phone 1" i can access only the package but how to access the sub settings.

Please help!!

Hey having trouble with Swift 3. I have the following code:

public var urlSession : URLSession?
self.urlSession = URLSession(configuration: URLSessionConfiguration.default,
            delegate: self,
            delegateQueue: OperationQueue.main)

I am getting the following error message: "URLSession produces (), not the expected contextual result type URLSession?"

What am I doing wrong here?

Firstly refer to the graphic show below:

enter image description here

I have an NSArray that contains 9 Elements. Each of these 9 elements contain a further 5 Elements.

What I would like to do is take the [*][1] from each an place them into another which will only contain these dates.

How is this best achieved ??

How I can run Xcode 7.3.1 on a new mac OS Sierra? For now I always get crash on start.

enter image description here

We do have several Components in our product which are

  1. Component A
  2. Component B
  3. Component C

Dependencies are (if unmet the system fails):

A <-> B
B <-> C

We are currently creating a build pipeline and finally the Software for each component gets packaged into a single firmware image:

A -> Output A
B -> Output B
C -> Output C

Output A + Output B + Output C = Firmware

The firmware gets packed with some documentation and will then be deployed. Deployments should happen every week to testing and every 2-4 weeks to production.

Firmware + Docs = Deployed Software

My problem is now:

  • How do i ensure compatibility between A,B and C given the fact that they are all developed by different teams?

    I saw this question here Looking for best practice for version numbering of dependent software components

    We do have version numbers in place for A,B and C and the overall Firmware has one as well. Are there any best practices or ways to do it?

  • How do i track back compatibility? (Besides looking into the packaged firmware and see which versions got included at a certain point in time)

    I thought about using git tags here and put the Firmware Version number (only shipped products) as a tag on A,B,C.

I am tasked with redesigning an existing catalog processor and the requirement goes as below Requirement I have 5 to 10 vendors(each vendor can have multiple stores) who would provide me with 'XML' file per store. Basically, 1 products xml file per Store, and multiple Store files per Vendor. Max file size can be 500 MB and min can be 100 MB Avg products per file could be 100,000.

Sample xml format could be like this ... ... ...

It doesnt take more than 30 mins to download the file per store, and these files are updated once per day or every 3 to 6 hours.

Now priority requirement is that, the product details are highly unorganized and these files have to organized, processed(10+ processes) and converted to another common object(json) and then file stored in Cassandra.

My technology head advised me to design with Apache Flink and Kafka on top of HDFS, where flink directly stream the files from the vendor servers and start processing them while streaming.

My view was that, either case the files are of finite size and there is not much need to stream them. So thought of having a standalone scheduler come downloader to download and load the files to HDFS. As soon as the files are loaded to HDFS, I can trigger the Flink processing and store the same in Cassandra.

My question here is that, knowing the files are of finite size and finite counts irrespsective of the number of vendors, Is stream processing a overkill or a Batch processing would be a latency burden later?

To build .so files, I used: g++ -c -fPIC func.cpp g++ -shared func.o -o libfunc.so

I was under the impression -fPIC implies position independent code which means it can be loaded anywhere in memory which means it will be loaded by the dynamic loader on requirement basis (when a function exposed by that lib interface is called by a running program). But this doesnt seem to be the case. The above generated .so file is being referenced/loaded when I execute the calling program and before a function in that lib is called. (I think this is LOAD TIME LINKING?.) So, what are the steps so that I can create a .so file so that the loading of library into RAM is deferred until the corresponding function from the lib is called? (Should I do dlopen() call for this or some different options in g++ commands will do?).

I have a RecyclerView, and after I scroll, the values of my items in my adapter are swapping. This is obviously an issue with the recycling of the view, with the underlying data not being cleared.

However, i've read dozens of iterations of this question, but am unable to decipher a clear fix from any of the answers, and my problem is persisting.

I am setting the Adapter to have Stable Ids, overriding the getItem, getItemId, and getItemCount methods, and - i think - performing the correct check on my onBindViewHolder method to tell if my data is clean or not... but this last part is confusing to me, as I am unsure as to what I should be performing my conditional on (where I feel the bulk of the answers to these questions are lacking)...

Here's some relevant code:

public class MenuQueryAdapter extends ParseRecyclerQueryAdapter<MenuItem, MenuQueryAdapter.MenuViewHolder> {

    public MenuQueryAdapter(ParseQueryAdapter.QueryFactory<MenuItem> factory, boolean hasStableIds) {
        super(factory, hasStableIds);// hasStableIds set to TRUE

    public MenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MenuViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_item, parent, false));

    public void onBindViewHolder(MenuViewHolder holder, int position) {
        MenuItem menuItem = getItem(position);

    public MenuItem getItem(int position) {
        //return super.getItem(position);
        if (menuItemList != null && menuItemList.size() > 0) {
            return menuItemList.get(position);
        return super.getItem(position);

    public long getItemId(int position) {
        return position;

    // View Holder
    public static class MenuViewHolder extends RecyclerView.ViewHolder {

        MenuItem menuItem;

        TextView title;
        TextView price;
        TextView summary;
        TextView itemCount;

        TextView  calorieLabel;
        TextView  proteinLabel;
        TextView  fatLabel;
        TextView  carbsLabel;
        TextView  fiberLabel;

        ParseImageView imageView;

        private String objectId = "";
        private boolean active = true;
        private boolean inStock = true;
        private boolean cSoon = false;
        private boolean hasNutrition = false;

        MenuViewHolder(View itemView) {

            title = (TextView) itemView.findViewById(R.id.menu_title_label);
            price = (TextView) itemView.findViewById(R.id.menu_price_label);
            summary = (TextView) itemView.findViewById(R.id.menu_summary);

            calorieLabel = (TextView) itemView.findViewById(R.id.menu_label_calorie_value);
            proteinLabel = (TextView) itemView.findViewById(R.id.menu_label_protein_value);
            fatLabel = (TextView) itemView.findViewById(R.id.menu_label_fat_value);
            carbsLabel = (TextView) itemView.findViewById(R.id.menu_label_carbs_value);
            fiberLabel = (TextView) itemView.findViewById(R.id.menu_label_fibre_value);

            imageView = (ParseImageView) itemView.findViewById(R.id.menu_main_image);

            // Containers
            final RelativeLayout activeView = (RelativeLayout) itemView.findViewById(R.id.menu_top_view_active);
            final RelativeLayout inactiveView = (RelativeLayout) itemView.findViewById(R.id.menu_top_view_inactive);

            View.OnClickListener clickListener = new View.OnClickListener() {
                public void onClick(View v) {
                    active = !active;

            final RelativeLayout topView = (RelativeLayout) itemView.findViewById(R.id.menu_top_view);

            final ImageButton info = (ImageButton) itemView.findViewById(R.id.menu_info_button);


        public void bindItem(MenuItem item) {
            menuItem = item;

            menuItem.populateData(); // gets data from DB

            if( !menuItem.getTitle().equals(enroot.getContext().getResources().getString(R.string.menu_title)) ) {

                if (menuItem.getInt(EnrootConstants.kERItemInStockKey) <= 0) {
                    inStock = false;
                if (menuItem.getBoolean(EnrootConstants.kERItemComingSoonKey) && inStock) {
                    cSoon = true;
                if (menuItem.getList(EnrootConstants.kERItemNutritionKey) != null && menuItem.getList(EnrootConstants.kERItemNutritionKey).size() > 0) {
                    hasNutrition = true;

                // Id
                objectId = menuItem.getObjectId();
                if (mOnItemChangedListener != null) {

                // Stock
                RelativeLayout ooStock = (RelativeLayout) itemView.findViewById(R.id.menu_soldout);
                if (!inStock) {

                // Coming Soon
                RelativeLayout comingSoon = (RelativeLayout) itemView.findViewById(R.id.menu_comingsoon);
                if (cSoon) {

                // Nutrition
                if (!hasNutrition) {
                    RelativeLayout nutritionOverlay = (RelativeLayout) itemView.findViewById(R.id.menu_nutrition_group);

                // Minus
                final ImageButton minus = (ImageButton) itemView.findViewById(R.id.menu_btn_minus);
                if (inStock && !cSoon) {
                    minus.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            if (mOnItemChangedListener != null) {
                                mOnItemChangedListener.onPriceSubtracted(objectId, getAdapterPosition());
                } else {

                // Plus
                final ImageButton plus = (ImageButton) itemView.findViewById(R.id.menu_btn_plus);
                if (inStock && !cSoon) {
                    plus.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            if (mOnItemChangedListener != null) {
                                mOnItemChangedListener.onPriceAdded(objectId, getAdapterPosition());
                } else {
            else {

        void clearItem() {


            objectId = "";
            active = true;
            inStock = true;
            cSoon = false;
            hasNutrition = false;


    } /* eoc holder */

    } /* eoc adapter */

So... I see a lot of talk about simply overriding the getItem and/or getItemId (which makes sense if you have Stable Ids), but that doesn't seem to have any effect. I've even had setIsRecyclable set to false on the ViewHolder, to no effect.

I'm stuck... would love to hear if I'm doing something dreadfully wrong...

I just need your help. I want to develop an application which includes TableLayout and also i want to add n number of rows at run time. i have tried searching many stuffs, could'nt find the possible way. So anyone can help or provide any reference.. Thanks in advance

I was using the below code for blocking incoming call till I update android studio to 2.3 it was working once I have done it the same code stopped to work. I don't know why. Please help me to solve this problem.

TelephonyManager tm;
com.android.internal.telephony.ITelephony telephonyService;
(TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
Class c1 = Class.forName(tm.getClass().getName());
Method m1 = c1.getDeclaredMethod("getITelephony");
telephonyService = (ITelephony) m1.invoke(tm);

The issue here is after updating android studio to 2.3 the telephonyService.endCall() is producing false. Is there any possible solutions or is there any other alternate way. I have added the below in manifest too.

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />

Thanks in Advance

Hi I have just done a conversion to Swift 3.0 and have had quite a few errors returned. The first one is:

Ambiguous reference to member 'dataTask(with:completionHandler:)' Found this candidate

Does anyone have a solution?

The code that gives this is:

var request = NSMutableURLRequest(url: URL(string: urlString)!,
                cachePolicy: .useProtocolCachePolicy,
                timeoutInterval: 10.0)
            request.httpMethod = "GET"
            request.allHTTPHeaderFields = headers

            var downloadTask = URLSession.shared.dataTask(with: request, completionHandler: {(data, response,error) -> Void in
                if (error != nil) {
                    completionHandler(image: nil, url: urlString)

     let session = URLSession.shared
            var task = session.dataTask(with: request, completionHandler: {
                (data, response, error) -> Void in

                if (error != nil){

In XIB it works fine For me.

ThirdViewController *thirdVC = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];

// preload views to the memory
[thirdVC view];

// setup fromviews array and toviews array
NSArray *fromViews = [NSArray arrayWithObjects:self.imageView1, self.imageView2, self.label1, nil];
NSArray *toViews = [NSArray arrayWithObjects:thirdVC.imageView1, thirdVC.imageView2, thirdVC.label1, nil];

[self pushViewController:thirdVC fromViews:fromViews toViews:toViews duration:1.0];

But when I preload views to the memory in storyboard, I don't know how I can use that.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"FourthVC" bundle:nil];
FourthVC *vc = [sb instantiateViewControllerWithIdentifier:@"FourthVC"];

NSArray *fromViews = [NSArray arrayWithObjects:self.imageView1, self.imageView2, self.label1, nil];

NSArray *toViews = [NSArray arrayWithObjects:vc.imageView1, vc.imageView2, vc.label1, nil];

[self pushViewController:vc fromViews:fromViews toViews:toViews duration:1.0];

Anyone can suggest how I can preload the views in storyboard?