i am having few counter variables that i need to store for their values even when that app is closed or kill or rotated.i know about savedinstancestate,but i dont know how to use it.here's my code i want to save the following values of the variables 1.allahuakbarweek 2.allahuakbarmonth 3.subhanallahweek 4.subhanallahmonth 5.alhamdulilahweek 6.alhamdulilahmonth

here's my code it is a fragment

    package com.farme5.mosquelocator;





import android.os.Bundle;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
 import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView; 

    public class FragTasbeeh extends Fragment  {

    private Spinner spinner;
    public static final String[] items={"Alhamdulilah","SubhanAllah","AllahuAkbar"};
    ImageView ivIcon;
       TextView tvItemName;
       TextView mview;
       TextView wview;
      Button add,reset;
        int counter=0;
        int week,allahuakbarweek,allahuakbarmonth,subhanallahweek,subhanallahmonth,alhamdulilahweek,alh amdulilahmonth;
        int month;
        int count,alhamdulilahcount,subhanallahcount,allahuakbarcount;
    Time t=new Time(Time.getCurrentTimezone());

    public static final String IMAGE_RESOURCE_ID = "iconResourceID";
    public static final String ITEM_NAME = "itemName";
      FragmentManager frg=getFragmentManager();
      Fragment fragment=null;

      public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.tasbeeh,container, false);
        if(savedInstanceState==null)
        {
            alhamdulilahcount=0;
            alhamdulilahweek=0;
            alhamdulilahmonth=0;
        }
        else
        {

            savedInstanceState.putInt("alhamdulilahcount", alhamdulilahcount);
            savedInstanceState.putInt("alhamdulilahweek", alhamdulilahweek);
            savedInstanceState.putInt("alhamdulilahmonth", alhamdulilahmonth);
        }

        return view;

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        add=(Button)getActivity().findViewById(R.id.button1);
        tvItemName=(TextView)getActivity().findViewById(R.id.textView1);
        wview=(TextView)getActivity().findViewById(R.id.textView2);
        mview=(TextView)getActivity().findViewById(R.id.textView3);

        Spinner dropdown = (Spinner)getActivity().findViewById(R.id.spin);

        ArrayAdapter<String> adapter = new ArrayAdapter<String> (this.getActivity(),android.R.layout.simple_spinner_item, items);
            dropdown.setAdapter(adapter);
            dropdown.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {
                // TODO Auto-generated method stub
                switch(position){

                case 0: 

                    tvItemName.setText(alhamdulilahcount+"");
                    mview.setText(alhamdulilahmonth+"");
                    wview.setText(alhamdulilahweek+"");
                alhamdulilahcount();
                break;
                case 1:
                    tvItemName.setText(subhanallahcount+"");
                    mview.setText(subhanallahmonth+"");
                    wview.setText(subhanallahweek+"");
                    subhanallahcount();
                    break;
                case 2:
                    tvItemName.setText(allahuakbarcount+"");
                    mview.setText(allahuakbarmonth+"");
                    wview.setText(allahuakbarweek+"");
                    allahuakbarcount();
                    break;
                    default:
                        break;
                }

            }

            private void allahuakbarcount() {
                // TODO Auto-generated method stub
                count=0;
                month=0;
                week=0;
                add = (Button)getActivity().findViewById(R.id.button1);
                reset = (Button)getActivity().findViewById(R.id.button2);
                reset.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        allahuakbarcount=0;
                        tvItemName.setText(allahuakbarcount+"");

                    }
                });
                add.setOnClickListener(new OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        allahuakbarcount++;
                week++;
                        month++;
                        allahuakbarweek++;
                        allahuakbarmonth++;
                        tvItemName.setText(allahuakbarcount+"");
                        mview.setText(allahuakbarmonth+"");
                        wview.setText(allahuakbarweek+"");


                    }
                });
            }

            private void subhanallahcount() {
                // TODO Auto-generated method stub

                count=0;
                add = (Button)getActivity().findViewById(R.id.button1);
                reset = (Button)getActivity().findViewById(R.id.button2);
                reset.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        subhanallahcount=0;
                        tvItemName.setText(subhanallahcount+"");

                    }
                });
                add.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        subhanallahcount++;
                        week=week+count;
                        month=month+count;
                        subhanallahweek++;
                        subhanallahmonth++;

                        tvItemName.setText(subhanallahcount+"");
                        mview.setText(subhanallahmonth+"");
                        wview.setText(subhanallahweek+"");



                    }
                });
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });         }





    public  void alhamdulilahcount() {
        // TODO Auto-generated method stub
        alhamdulilahcount=0;
        add = (Button)getActivity().findViewById(R.id.button1);
        reset = (Button)getActivity().findViewById(R.id.button2);
        reset.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                alhamdulilahcount=0;
                tvItemName.setText(alhamdulilahcount+"");

            }
        });
        add.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                alhamdulilahcount++;
                week++;
                month++;
                alhamdulilahweek++;
                alhamdulilahmonth++;
                tvItemName.setText(alhamdulilahcount+"");
                mview.setText(alhamdulilahmonth+"");
                wview.setText(alhamdulilahweek+"");


            }
        });

    }


    /* (non-Javadoc)
     * @see android.app.Fragment#onSaveInstanceState(android.os.Bundle)
     */
    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onSaveInstanceState(savedInstanceState);
        savedInstanceState.putInt("alhamdulilahcount", alhamdulilahcount);
        savedInstanceState.putInt("alhamdulilahweek", alhamdulilahweek);
        savedInstanceState.putInt("alhamdulilahmonth", alhamdulilahmonth);
    }
    }

How can i scan my android app for potential security vulnerabilities that can cause damage to my users & company in an affordable cost?

I am trying to send the bundle data from the activity class to the fragment class, but I have been getting the NPE error. I've researched a bit on Stackoverflow and tried a few different things, but none seemed to work.

I have another activity class sending the intent to the MainActivity class. So the bundle from the MainActivity.java is definitely not null when it is sent to the myFragment class.

Please help! Thank you! :D

MainActivity.java

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.activity_main);

      Bundle extras = getIntent().getExtras();
      if (extras != null) {
        Bundle bundle = new Bundle();
        String value = extras.getString("TEST36");
        bundle.putString("TEST36", value);
        myFragment fragInfo = new myFragment();
        fragInfo.setArguments(bundle);
      }
  }
}

myFragment.java

public class myFragment extends Fragment{
   @Override
   public View onCreateView(LayoutInflater inflater, ViewGroup parent,
        Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_xml, parent, false);

   @Override
   public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Bundle bundle = getArguments();                                             
    String myMode = bundle.getString("TEST36");
   }
 }

I've installed

  • Android SDK
  • Apache Ant
  • Phonegap (via node.js)
  • (all in Windows 7)

Unfortunately I had an old version from the Android SDK & Apache Ant on my PC. Now I have the problem everytime I run

phonegap run myProjectName

it says this

...
Buildfile: D:\Dev\Apps\testApp\platforms\android\build.xml
  [taskdef] Could not load definitions from resource emma_ant.properties. 
            It could not be found.

-set-mode-check:
-set-debug-files:
-check-env:
  [checkenv] Android SDK Tools Revision 23.0.0
  [checkenv] Installed at D:\Software\ADT\sdk

BUILD FAILED
D:\Software\ADT\sdk\tools\ant\build.xml:483: The SDK Build Tools revision (17.0.0)is too low for project 'HelloWorld'. Minimum required is 19.1.0

In my new installation of the Android SDK the folder is now

D:\Dev\ADT  // --> not D:\Software\ADT

I changed the windows ENVIROMENTS: PATH, ANT_HOME, ANDROID_HOME. But Phonegap always says that the SDK is installed in that old folder.

What else have I to change here? I can't find it. Phonegap seems to read some configuration I haven't found yet. Because the problem occurs while run Phonegap. I deleted Phonegap and installed it again but that doesn't fix the problem. So I guess somewhere in windows has to be a config that hold this SDK.DIR with the old values.

In my android app, I have a tableLayout which I want to expand/collapse. I tried many solutions from many stackoverflow pages, but none work great.

I found this site, which gives the best solution, but its still not perfect. When I expand or collapse, you see the view for 1 frame in a totally random place (blink of an eye)...

http://softsoulandroid.wordpress.com/2012/01/21/android-view-expandcollapse-animation/

This is the code I have so far

package animation;

import java.lang.reflect.Method;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.animation.Animation;
import android.view.animation.Transformation;

public class Animate {

    public static Animation expand(final View v, final boolean expand) {
        try {
            Method m = v.getClass().getDeclaredMethod("onMeasure", int.class,int.class);
            m.setAccessible(true);
            m.invoke(v,MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                MeasureSpec.makeMeasureSpec(((View) v.getParent()).getMeasuredWidth(),MeasureSpec.AT_MOST));
        } catch (Exception e) {
            e.printStackTrace();
        }

        final int initialHeight = v.getMeasuredHeight();
        if (expand) {
            v.getLayoutParams().height = 0;
        } else {
            v.getLayoutParams().height = initialHeight;
        }
        v.setVisibility(View.VISIBLE);

        Animation a = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                int newHeight = 0;
                if (expand) {
                    newHeight = (int) (initialHeight * interpolatedTime);
                } else {
                    newHeight = (int) (initialHeight * (1 - interpolatedTime));
                }
                v.getLayoutParams().height = newHeight;
                v.requestLayout();
                if (interpolatedTime == 1 && !expand) {
                    v.setVisibility(View.GONE);
                }
            };

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };

        a.setDuration(500);
        return a;
    }
}

and code to call it

    toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
            //table.setVisibility(arg1 ? View.VISIBLE : View.GONE);

            Animation anim = Animate.expand(table, arg1);
            table.startAnimation(anim);
        }
    });

Does anyone know what is wrong and how to fix it?

Thanks

This is a class which extends Thread and implements the run() function:

public class TestThread extends Thread{
public Handler handler;
public TestThread(){

    handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
        }
    };
}
public Looper getLooper(){
    return Looper.myLooper();
}
@Override
public void run() {
    // TODO Auto-generated method stub
        Looper.prepare();
        Looper.loop();      
}
}

Now in a button in the main activity I have this code:

TestThread t=new TestThread();
    t.start();  
    Handler h=new Handler(t.getLooper());
    h.post(new Runnable(){
        @Override
        public void run() {
            // TODO Auto-generated method stub
            while (true);
        }
    });

As far as I know this is supposed to put the runnable in the target Thread's message queue and the thread (not UI thread) will run it when possible. But this code blocks the UI. why does this happen? As you see I sent the target thread's looper to the Handler constructor and the handler should use that looper not the main thread's looper.

I want to capture the screen. Libgdx provides some functions defined in the ScreenUtils class.

For instance final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);

My problem is that it takes about 1-3 seconds to get that information. During that time the game loop is blocked and the user will define it as a lag.

Internally the ScreenUtils class, uses Gdx.gl.glReadPixels. If I run the ScreenUtils.getFrameBufferPixmap method in a thread, there is no lag, but it captures the screen at the wrong method, which is logical since the game loop runs and changes stuff.

Is it somehow possible to copy the GL context or save it and generate the Pixmap at a later point of time with the help of a Thread? Of course the copy/save operation should be done instantly, otherwise I don't spare anything.

I use ShapeRenderer to render my stuff onto the screen.

I am using SoundPool in order to play some sounds using timers in my applications. Does anyone know if there is an in-built queue where it will queue files and play them only when the previous files are finished?

Do I have to write my own implementation of a SoundPool queue?

My events management app has two types of views in the list view : a small simmple text view for not-so-important events and a complex view created with a FrameLayout.

in the onCreateView() of the adapter, I return these views depending upon the nature of the event.

if(convertView == null){
  if(important)
   // inflate the complex view
  else
   // inflate the simpler view
}  

This is all good when convertView is null. Due to the view recycling in Android, it may happen that the convertView returned to me is recycled from the simpler view and I now have to display the larger view. One dumb solution is to inflate new views all the time. However, this will kill performance.

Another way is to have invisible TextViews in both of them (visibility=gone) with predefined values and depending on what value is in them, I can inflate the views. To me, this seems like a hack rather than a real solution.

What is the right way to handle this situation?

I want to make an app allow user to set a time on which message has been send please help me what to do and how to do am done with text boxes and buttons and I am able to send message too but I don't know how to get device time and time from user to use if statement for message send

first after finishing by app i want to add AD to my app before i but it in google play , i use this to do it https://developers.google.com/mobile-ads-sdk/docs/ to do this i have to update my sdk , and after that i start getting problem trying to install the ADT first it cant found the update second after i get how to do it they asked me to go to Help/ Install new software and then what is already install and uninstall all the 22.0 . but after i uninstall it and before i install the new 23.0 when i try to open the eclips it give me this error the eclipse executable launcher was unable to locate its companion shared library
i download new ADT and try to instill the 23.0 i got this error

No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.adt.feature,23.0.2.1259578



Details: An error occurred while collecting items to be installed

session context was:(profile=DefaultProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.adt.feature,23.0.2.1259578 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.ddms.feature,23.0.2.1259578 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.gldebugger.feature,23.0.2.1259578 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.hierarchyviewer.feature,23.0.2.1259578 No repository found containing: osgi.bundle,com.android.ide.eclipse.ndk,23.0.2.1259578 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.ndk.feature,23.0.2.1259578 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.traceview.feature,23.0.2.1259578

ok i selove the last thing and update to 23.0 in the new ADT that i install my error was in http change it to https no i get this error in this IMG

IMG

ok i fix this also by right click on my app then properties then i choose project build target as android 4.4w but i get one new error is in all case .. case expressions must be constant expressions and .. import android.support.v7.appcompat.R.id; ... The import android.support.v7.appcompat.R cannot be resolved why nothing is working for me . my app was already done :(

I want to use a layout and not a drawable for my marker I am using with Google Maps Api 2 for an Android app.

Like this:

  Marker m = googleMap
                        .addMarker(new MarkerOptions()
                                .position(LOC)
                                .snippet(user)
                                .title(name)
                                .icon(BitmapDescriptorFactory.fromResource(R.layout.map_marker)));

However, it seems this is only designed for use from drawable folder.

I simply what an image with a background where I can change colors based on marker type. This is the layout I want to use:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="#222"
    android:id="@+id/llMarker">

    <ImageView
        android:id="@+id/ivMarker"
        android:layout_marginTop="5dp"
        android:layout_width="40dp"
        android:layout_height="40dp" />

</LinearLayout>

Pretty basic. How can I use this as a marker? (or at least replicate the end result that I am going for?)

The documents say you can use this:

fromResource (int resourceId)

So I assumed a layout might work.

I want to make a phonegap android app which displays the live camera feed as the activity background. am a fairly experienced phonegap developer but i have totally novice when it come to mainstream android app development .does anybody have an idea how to go about this .

I have this code in an xml inside the drawable folder:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <size android:width="90dp" android:height="90dp" />

                <solid android:color="#9933CC" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
            </item>
        </layer-list>
    </item>
    <item>
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <size android:width="90dp" android:height="90dp" />

                    <solid android:color="#AA66CC" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
            </item>
        </layer-list>
    </item>

</selector>

I use it to have an image with 2 states (to use as a button). Everything works as expected on emulator and devices.

I know that I can create different drawable xml and make a reference to achieve the same result.

I just switched to Android Studio and it shows me this mesage: Element XXX is not allowed here. It warns me about Layer-list and all the tags inside it. However, as I said, this code works just fine.

Should I switch my code into separated XMLs (knowing that I will only use them once) or is an "error" in the Android Studio's Inspector Code?

NOTE: I think my code can be optimized, but I haven't figured out how yet.

I'm creating a custom watch face and I would like to change the location of the battery icon on it. By default it is placed on the top left corner and I would like it to be positioned somewhere else on the taskbar.

Does anyone know how it can be done?

In Application i need to load a few Bitmaps on create. To save Memory i'm loading one image, rescale it by creating a scaledBitmap out of it, recycle the unscaled Bitmap on so on:

    bmpUnscaled = BitmapFactory.decodeResource(getResources(), R.drawable.cultivation_plant_resized_1);
      plant1 = Bitmap.createScaledBitmap(bmpUnscaled,(int) plant[0].getWidth(), (int) plant[0].getHeight(), true);
      bmpUnscaled.recycle();
    System.gc();
    bmpUnscaled = BitmapFactory.decodeResource(getResources(), R.drawable.cultivation_plant_resized_2);
      plant2 = Bitmap.createScaledBitmap(bmpUnscaled,(int) plant[0].getWidth(), (int) plant[0].getHeight(), true);
      bmpUnscaled.recycle();
    System.gc();

and so on...

I am doing this 10 Images, wich are scaled relative to the screen resolution. The orginal Image is a PNG (570x900 (max. 660KB))

Does anybody have some Ideas to save Memory simply? I'm desperate right now...

So I am not a very expert programmer "YET". I just have few questions about my approach to android and java.

1) Is it wrong that i search for help online alot?

2) I started android programming hardly 2 months ago. I started with Java and after few tutorials i moved directly to Android Studio. I didnt face much trouble when learning Java because i had previously worked on .Net for 2 years. Just wanted to ask if my approach is wrong because sometimes i just cant find a way forward.

3) I hardly code anything myself. Its not like i cant get things done. I have successfully implemented swipe views, fragments, list fragments and other XML design techniques but i dont code the entire thing myself. I look for a sample code online and copy it. Editing is not a problem because i understand every code I am coppying. Is this wrong. Should i stop it and start coding myself?

Please share your approach as a beginner?

Thanks

Why background color is ignored on Android 3.x? I also tried to change the background from manifest and I tried to enable hardware accelerator, but go from vertical and horizontal, and then vertical, it's works! How to solve?

I'm trying to implement a zooming function for my uni project. So my app loads a picture from the SD gallery. It has buttons for zooming and panning. I have to realise this project in emulator.

So far i have mostly found solutions for multitouch or pinch zoom. But i can't use multitouch since emulator doesn't allow it and it's also a requirement from my prof. i couldn't really find some substantial source on zooming with just mouse clicks on a button. any tips where/how to start?

thanks!

I'm doing a project using android. In that project I'm using microphone as a resource. In most cases, it works properly. But in some cases(some phones), It shows an error, of locking the resource(microphone). So how can i get the priority of the resource(microphone) or how can i snatch the resource from another program.

I am implementing a File Provider, followed the doc carefully but unable to use the files in the app itself or share any file.

Added manifest, created xml file for dir sharing, generating content uri, granting uri permission, tried sharing files with cache, external, internal dir but nothing is working.

Searched the net but found nothing which is missing in the code.

Below is the code:

Manifest:

 <provider
     android:name="android.support.v4.content.FileProvider"
     android:authorities="package.widget.fileprovider"
     android:exported="false"
     android:grantUriPermissions="true" >
     <meta-data
         android:name="android.support.FILE_PROVIDER_PATHS"
         android:resource="@xml/filepaths" />
  </provider>

filepaths.xml

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="widgetDoc" path="."/>
</paths>

GetUri:

private Uri getFileUri(Context context, String name){
        File newFile = new File(context.getCacheDir() + File.separator + StorageUtil.INTERNAL_DIR, name);
        Uri contentUri = FileProvider.getUriForFile(context, "package.widget.fileprovider", newFile);       

        return contentUri;
    }

Code to access pdf file:

Intent target = new Intent(Intent.ACTION_VIEW);
Uri uri = getFileUri(getApplicationContext(), file);
target.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
target.setDataAndType(uri,"application/pdf");
Intent intent = Intent.createChooser(target, "Choose Pdf Viewer...");
startActivity(intent);

Code to access image:

imageview.setImageURI(getFileUri(getApplicationContext(), file));

Kindly help me out where I am going wrong, not even able to use these files in my own app too.

Thanks in advance.