Im working with a travel app and I need this Viewflipper as a banner of the travel spots. I'm very new to android studio. Please help me.

My MainActivity.java

package com.compscitutorials.basigarcia.navigationdrawervideotutorial;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

 public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

private boolean viewIsAtHome;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    displayView(R.id.nav_camara);
    final ViewFlipper MyViewFlipper = (ViewFlipper)findViewById(R.id.viewflipper);
    final Animation fadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    final Animation fadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
    MyViewFlipper.setAutoStart(true);
    MyViewFlipper.setInAnimation(fadeIn);
    MyViewFlipper.setInAnimation(fadeOut);
    MyViewFlipper.setFlipInterval(3000);
    MyViewFlipper.startFlipping();


    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

    //How to change elements in the header programmatically


    navigationView.setNavigationItemSelectedListener(this);
}
public void displayView(int viewId) {
    Fragment fragment = null;
    String title = getString(R.string.app_name);

    switch (viewId) {
        case R.id.nav_camara:
            fragment = new MainFragment();
            title  = getString(R.string.home);
            viewIsAtHome = true;

            break;
        case R.id.nav_touristspot:
            fragment = new TouristFragment();
            title = getString(R.string.t_spot);
            viewIsAtHome = false;
            break;

        case R.id.nav_hotels:
            fragment = new HotelFragment();
            title = getString(R.string.hotel);
            viewIsAtHome = false;
            break;
        case R.id.nav_mals:
            fragment = new MallsFragment();
            title = getString(R.string.malls);
            viewIsAtHome = false;
            break;
        case R.id.nav_restaurants:
            fragment = new RestaurantFragment();
            title = getString(R.string.rest);
            viewIsAtHome = false;
            break;
        case R.id.nav_govoff:
            fragment = new GovOffFragment();
            title = getString(R.string.govoffz);
            viewIsAtHome = false;
            break;
        case R.id.nav_hospitals:
            fragment = new HospitalFragment();
            title = getString(R.string.hospital);
            viewIsAtHome = false;
            break;
        case R.id.nav_airport:
            fragment = new AirportFragment();
            title = getString(R.string.airp);
            viewIsAtHome = false;
            break;
        case R.id.nav_bust:
            fragment = new BusterminalFragment();
            title = getString(R.string.bterm);
            viewIsAtHome = false;
            break;
        case R.id.nav_wharf:
            fragment = new WharfFragment();
            title = getString(R.string.pier);
            viewIsAtHome = false;
            break;
        case R.id.nav_helpd:
            fragment = new GalleryFragment();
            title = getString(R.string.helpd);
            viewIsAtHome = false;
            break;
        case R.id.nav_rate:
            fragment = new GalleryFragment();
            title = getString(R.string.rus);
            viewIsAtHome = false;
            break;
        case R.id.nav_cas:
            fragment = new GalleryFragment();
            title = getString(R.string.com);
            viewIsAtHome = false;
            break;
    }

    if (fragment != null) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.fragment_container, fragment);
        ft.commit();
    }

    // set the toolbar title
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(title);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);

}
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    }
    if (!viewIsAtHome) { //if the current view is not the News fragment
        displayView(R.id.nav_camara); //display the News fragment
    } else {
        moveTaskToBack(true);  //If view is in News fragment, exit application
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    displayView(item.getItemId());
    return true;
}
}

I'm getting an error this in line of code. It is in the onCreate in MainActivity.java

final ViewFlipper MyViewFlipper = (ViewFlipper)findViewById(R.id.viewflipper);
    final Animation fadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    final Animation fadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
    MyViewFlipper.setAutoStart(true);
    MyViewFlipper.setInAnimation(fadeIn);
    MyViewFlipper.setInAnimation(fadeOut);
    MyViewFlipper.setFlipInterval(3000);
    MyViewFlipper.startFlipping();

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<include layout="@layout/app_bar_main" android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView android:id="@+id/nav_view"
    android:layout_width="wrap_content" android:layout_height="match_parent"
    android:layout_gravity="start" android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

And this is where my viewflipper is at.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.compscitutorials.basigarcia.navigationdrawervideotutorial.MainFragment">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ViewFlipper
    android:id="@+id/viewflipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
</ViewFlipper>
</LinearLayout>
</RelativeLayout>

Lets say i have a asyncTask like this:

 void startAsyncTask() {
    new AsyncTask<Void, Void, Void>() {
        @Override protected Void doInBackground(Void... params) {
            int i=0;
            while(i!=Integer.MAX_VALUE){//stay alive for long time
              i++;
        }
}
    }.execute();
}

For those who dont know a asyncTask just creates a background thread. and anonymous classes are really non-static inner classes.

Now lets say in the activity (main thread) i call startAsyncTask()

the thread will take a little while to complete (let's imagine at least a few minute for this example).

During the background threads lifetime, lets imagine the activity gets destroyed and its time to garbage collect the activity. Since the asyncTask has an implicit reference to the outer class (the activity) the activity will leak and will not be garbage collected.

But my question is the following: After some time, the child thread will eventually finish. Can the GC attempt to free memory again or is the activity forever leaked ? What i want to know really is if the child thread finishes in a reasonable amount of time will the activities memory be freed or is it only on the first attempt the GC tries and after that attempt the memory is forever lost ?

i got this error:

    java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:299)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    at java.lang.Thread.run(Thread.java:849)
Caused by: java.lang.NoClassDefFoundError: org.jsoup.Jsoup

the problem is that not all Android version get this error. For example Android 6 works well whereas Android 4.3 throws this error. Could somebody help me what to do?

my build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId 'com.test'
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:support-v4:23.2.1'
    compile 'se.simbio.encryption:library:1.2.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile files('libs/jsoup-1.9.2.jar')
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
}

I'm using a slighly modified version CardStackUI libary here: https://github.com/mutualmobile/CardStackUI. The default behavior of the library does not take the size that the CardStackLayout has available to it (it just uses the screen height). I need to adjust the size of the cards in the Card Stack to fit better within the space the Card Stack has available. So I figured I would let the CardStackLayout have its layout performed, get its height, and adjust the card heights accordingly. However I'm running into problems where no cards are drawn on the screen. The following code will draw the cards:

static boolean first = true;
....
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            View rootView;

                    rootView = inflater.inflate(R.layout.fragment_emotionalintel, container, false);
                    mCardStackLayout = (CardStackLayout) rootView.findViewById(R.id.cardStack);
                    mCardStackLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                        @Override
                        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                            CardStackLayout layout = (CardStackLayout) v.findViewById(R.id.cardStack);
                            MyCardStackAdapter adapter = new MyCardStackAdapter(ma_context);
                            if (layout != null && first) {
                                adapter.setAvailableHeight(mCardStackLayout.getHeight());
                                if(mCardStackLayout.getAdapter() != null  && (top != oldTop || bottom != oldBottom || left != oldLeft || right != oldRight)){
                                    mCardStackLayout.removeAdapter();
                                    Log.d(this.getClass().getName(),String.valueOf(mCardStackLayout.getChildCount()));
                                }
                                mCardStackLayout.setAdapter(adapter);
                                Log.d(this.getClass().getName(),String.valueOf(mCardStackLayout.getChildCount()));
                            }
                            first = false;
                        }
                    });

                return rootView;
            }
        }

If I change the if statement to layout != null && !first then the cards will no longer draw on screen. The same code will be executed it both cases, but the !first version just will be executed on subsequent calls to onLayoutChange(). Of course, I want to remove all this first business altogether so that the height of the cards will be adjusted each time the layout is changed. Why are the cards drawn if I set the adapter on the first call to onLayoutChange() but not subsequent ones?

If the computer that runs the Android Studio has an IP address of 192.168.0.2, and there is another computer whose address is 192.168.0.3, is it possible for an app that runs in the Android emulator to reach the computer (192.168.0.3) and vice versa? For example, the app connects to a server running on thr computer, or the web browser running on the server opens a web site hosted by the app running on the emulator.

I mean, using the Google's Android emulator, not third-party emulators.

This is usually possible with PC emulators if the network type is set to bridge mode.

Inside of the Android Developer Console I would like to have 2 applications, MyAppName and MyAppName-Staging. The only differences between these two apps would be:

  1. The API environment they point (prod vs. staging)

  2. One would be for external Play Store release while the other (MyAppName-Staging) would be intended only for internal users in my company.

Would I be allowed to use the same package/app ID for both of these or would I need to change the package ID for each one? My assumption is I would need to change it, if thats the case can I use the same code base but just change the app ID and rebuild the apk to achieve this?

For additional context I've built this app using Nativescript. So all packaging info is handled through a package.json file and code signing must be done through the CLI. I just want to make sure I can't code sign myself into a situation where I can't release my build to production (the MyAppName build) Thanks for any guidance.

I have an activity that I'd like to have a few views, an expandable list view, then a few more views. However, whenever the list view is expanded, it covers all views below the list view - am I missing something? Shouldn't the following view float down along the bottom of the child sections as expanded?

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="This shows successfully"/>
    <ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pgs_group_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ExpandableListView>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="This shows only if not expanded"/>

</LinearLayout>

For example, wrapping the ExpandableListView as shown in this answer, when it expands, it covers all other controls above and below - it even covers the ones above, which is a worse result than just alone. Any insight is appreciated!

Thanks, James

I'm trying to delete an item from the following list. But when I try to grab the key, it shows the user id key which is NsShnb2enJcYEkfeE2fiSzbDc6O2. But I want to grab the key of each post. For example, if the user clicks on the first item in the list, it should grab the key KSGhFSZg....

There are lots of answers to the similar questions but the structure of the database is quite different here.

enter image description here

Here is the code, I used.

mAdapter = new FirebaseRecyclerAdapter<Note, FirebaseNoteViewHolder>(Note.class, R.layout.item_note, FirebaseNoteViewHolder.class, mRef) {
    @Override
    public void populateViewHolder(FirebaseNoteViewHolder noteMessageViewHolder, final Note noteMessage, final int position) {
        noteMessageViewHolder.setTitle(noteMessage.getTitle());
        noteMessageViewHolder.setUpdatedDate(DateFormat.getInstance().format(noteMessage.getDataModified()));

        noteMessageViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Toast.makeText(getActivity(), noteMessage.getDataModified().toString(), Toast.LENGTH_LONG).show();

                databaseReference.orderByChild("dataModified").equalTo(noteMessage.getDataModified().toString()).addListenerForSingleValueEvent(
                        new ValueEventListener() {
                            @Override
                            public void onDataChange(DataSnapshot dataSnapshot) {

                                String key = dataSnapshot.getKey();

                                Toast.makeText(getActivity(), key, Toast.LENGTH_LONG).show();
                            }


                            @Override
                            public void onCancelled(DatabaseError databaseError) {

                            }
                        });
            }
        });
    }
};   

enter image description here

Thanks in advance!

ERROR: _factory_client_recv: Unknown camera factory query name in ''

Below are the configuration setting for the emulator

AVD Name: Nexus 5 API 23 RAM: 1536 VM Heap: 1GB Internal Storage: 800MB Camera: None Graphics: Auto

I am creating a chat application using Realm 1.2.0 for Android.

Here are two minimized models I created:

public class Room extends RealmObject {

    private String name;

    private RealmList<Message> messages;

}

public class Message extends RealmObject {

    @PrimaryKey
    private long id;

    private String text;

}

Using these models, I can get all messages in a specific room. The problem is, I also want to access the room from a message.

For example, this would be possible (accessing the childs from the parent):

room.getMessages()

But I also want to access the parent from the child, like this:

message.getRoom()

Is this possible in Realm without manually querying all the rooms again?

I am developing an Android app. In my app I need to record audio using AudionRecord and need to play it. But throwing error when play the recorded pcm file. The main problem is I cannot log know the error as well because I have to test on real device and cannot run on emulator. Because when I run on emulator and record, my application crash. But please see what is wrong with my code below.

This is my activity

public class MainActivity extends AppCompatActivity {

    Boolean recording;
    private Thread recordingThread = null;
    DataOutputStream dataOutputStream;
    short[] audioData;


    private Button btnPlay,btnStop,btnRecord;
    private String outputFile = null;
    //outputFile = Environment.getExternalStorageDirectory().getAbsolutePath()+"/recording.3gp";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initialize();
        initViews();
        setUpViews();
    }

    private void initialize()
    {

    }

    private void initViews()
    {
        btnPlay = (Button)findViewById(R.id.btn_play);
        btnRecord = (Button)findViewById(R.id.btn_record);
        btnStop = (Button)findViewById(R.id.btn_stop);
    }

    private void setUpViews()
    {
        btnRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startRecord();
            }
        });

        btnStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                recording = false;
                Toast.makeText(getBaseContext(),"Stopped",Toast.LENGTH_SHORT).show();
            }
        });

        btnPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                playRecord();
            }
        });
    }

    private void startRecord(){

        File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");

        try {
            file.createNewFile();

            OutputStream outputStream = new FileOutputStream(file);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
            dataOutputStream = new DataOutputStream(bufferedOutputStream);

            final int minBufferSize = AudioRecord.getMinBufferSize(11025,
                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT);

            audioData = new short[minBufferSize];

            final AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                    11025,
                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT,
                    minBufferSize);

            audioRecord.startRecording();

            Toast.makeText(getBaseContext(),"Recording",Toast.LENGTH_SHORT).show();


            recordingThread = new Thread(new Runnable() {
                public void run() {
                    while(recording){
                        int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
                        for(int i = 0; i < numberOfShort; i++){
                            try{
                                dataOutputStream.writeShort(audioData[i]);
                            }
                            catch (IOException e)
                            {
                                Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }
            }, "AudioRecorder Thread");

            audioRecord.stop();
            dataOutputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private void playRecord(){

        File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");

        int shortSizeInBytes = Short.SIZE/Byte.SIZE;

        int bufferSizeInBytes = (int)(file.length()/shortSizeInBytes);
        short[] audioData = new short[bufferSizeInBytes];

        try {
            InputStream inputStream = new FileInputStream(file);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
            DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);

            int i = 0;
            while(dataInputStream.available() > 0){
                audioData[i] = dataInputStream.readShort();
                i++;
            }

            dataInputStream.close();

            AudioTrack audioTrack = new AudioTrack(
                    AudioManager.STREAM_MUSIC,
                    11025,
                    AudioFormat.CHANNEL_CONFIGURATION_MONO,
                    AudioFormat.ENCODING_PCM_16BIT,
                    bufferSizeInBytes,
                    AudioTrack.MODE_STREAM);

            audioTrack.play();
            audioTrack.write(audioData, 0, bufferSizeInBytes);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

The problem is with playing the recorded pcm. When I click play button, application throws fatal error and stopped. I cannot log the error as well. The pcm file really exists at the defined path as well. Please what is wrong with my code? Why cannot play? Please help me. Please.

I am working on an application that has common database which is using "SQLite-net pcl" .net library in Xamarin. I am able to use this database in my Android section.

My question is if I can make this database available to other applications on Android OS. I am well versed with Content Providers that are capable of doing this. Can I use Content Provider on top of the database created using "SQLite-net pcl" library ?

So, here the database consists in the Portable section and in future if I want to create an iOS application, then with a little bit of code in native iOS section I can have an iOS application with the same database running.

I want to import HTML codes from a specific URL using Jsoup package. please help. thank you.

I have created a Mapping which generates an XML target. Now I need to wrap the XML into a SOAP envelope. What is best way to approach this? I am new to Informatica. Thank you.

Hi Im using the GoogleMaps SDK for places in my app (using essentialy the Autocomplete feature) and I saw that its now possible to use only GooglePlaces SDK (the GoogleMaps SDK has a big size -130MB in my .ipa file)
migration link here

I followed the instructions but I am now getting a lot of 'Use of unresolved identifier' like GMSPlaceClients ,CLLocationDegrees or GMSAutocompleteResultsViewController althought they suppose to be in the GooglePlaces SDK
any ideas what am I missing? thanks for your help

React-router does not appear to be working when I use the iOS 'add to home screen' function. It works fine in the browser, but when I try and click links when opened via the home screen the links no longer work. Initially I thought it had to do with browserHistory(), but I've since switched to hashHistory

const history = syncHistoryWithStore(hashHistory, store)

My onClick method is using

this.context.router.push()

Has anyone encountered this before, and if so is there a fix for this?

communication waste is the time spent in communication between team members in the following cases:

  1. delivering features which are not needed by the customer
  2. delivering partial features (analysis, design, or testing is done, but the feature is canceled before it is completed and delivered)

Any other type of communication should be productive, even if it can be squeezed a bit.

can any one give an advice how to calculate these 2 items mentioned above

thanks

I have a profile resource. Profiles can have a parent and an arbitrary number of child profiles.

What's the best way to model this in a RESTful scenario?

I thought of a number of different solutions, each with pros and cons:

/profiles/:profile_id/children

+ it's clear that we are querying the profile resource

- the last fragment of the URL doesn't state that we will return a list of profiles

/parents/:parent_id/profiles

+ it's not clear that we are querying the profile resource

- the last fragment of the URL clearly states that we will return a list of profiles

/profiles/:profile_id/profiles

+ it's clear that we are querying the profile resource

+ the last fragment of the URL clearly states that we will return a list of profiles

- the hierarchical relationship might not be clear

Any thought or suggestions on how to clearly model this scenario?

I am new to Android and making my first real app and it uses the socket.io Java Client for communicating with my Node.JS server instance. I have recently discovered while testing that the OS can kill background apps whenever it feels necessary calling onSaveInstanceState() on the active Activity then when you switch back to the app it recreates the previous state using the Bundle passed as an argument in the onCreate() method.

So now that I know that, I need to implement a solution that would keep the app working as it should so I expect I will have to test a few solutions before I get the right one. And since it would be so time-consuming to just lock my screen and watch the server logs waiting for the

User disconnected

(which can take a lot of time for each try), I wondered if anyone here ever was in the same situation and figured a way to make the OS kill the app as soon as I lock the screen or hit the Volume Down button or something like that.

This question already has an answer here:

I'm getting this JSON from server :

"{\"id\":\"56\",\"image\":\"http:\/\/testing.vire-news.com\/\"}"

I have save in string and create JSONObject just like:

String response = new String(responseBody); //responseBody is Byte[]                  
JSONObject jObject = new JSONObject(response); //I have getting error here

I have check this string is valid JSON.

ERROR:

org.json.JSONException: Value {"id":"64","image":"http://testing.vire-news.com/"} of type java.lang.String cannot be converted to JSONObject

I want to get value of id and image value.

I have created a toggle button programmatically and using it but when it is running on device ,the status of toggle button is overlapping over the toggle button.like in the image enter image description here

the code for toggle is given below

  ToggleButton tb[];
            tb=new ToggleButton[len];
            tb[i]=new ToggleButton(this);

            LinearLayout.LayoutParams tbparams = new LinearLayout.LayoutParams
                    (90, LinearLayout.LayoutParams.WRAP_CONTENT);
            tbparams.setMargins(20, 0, 0, 0);
            tb[i].setBackgroundResource(R.drawable.bgtoggle);
            tb[i].setId(i+1);
            tb[i].setTextOff(" ");
            tb[i].setTextOn(" ");
            tb[i].setTag(stringList.get(i));
            tb[i].setPadding(4, 4, 4, 4);
            tb[i].setLayoutParams(tbparams);
            layout.addView(tb[i]);

    tb[i].setOnCheckedChangeListener(handleOnClick(
            tb[i], tb[i].getId(),tb[i].getTag(),stringList));

bgtoggle.xml

<?xml version="1.0" encoding="UTF-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">



    <!--<item android:drawable="@drawable/on" android:state_checked="true"/>

    <item android:drawable="@drawable/off" android:state_checked="false"/>
    <item android:drawable="@drawable/off"></item>-->

    <item android:drawable="@drawable/onsw" android:state_checked="true"/>

    <item android:drawable="@drawable/offsw" android:state_checked="false"/>
    <item android:drawable="@drawable/offsw"></item>


</selector>

please help