0

Lets say i have a listview as my main activity.On clicking an item it opens up a second activity.On clicking a button it opens a custom listview using volley library from this tutorial if you are following(http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/) However on clicking the button in the second activity to open my listview with volley,my app stops. The problem i figured started in the manifest as i'll post below. I have two Application classes as i am using Parse push notification library.But however only one application can be declared to open on startup in the manifest.So i implemented the answer on this question(how to handle multiple application classes in android) .It was after this that my app kept stopping when opening the third activity. So please help me achieve this.Thanks in advance.

Manifest snippet

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.stevekamau.snapt"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
 
<application
    android:name="com.stevekamau.snapt.ParseApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        
   </activity>
..............</activity>
<service android:name="com.parse.PushService" />
 
        <receiver android:name="com.parse.ParseBroadcastReceiver" >
         <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
              
            </intent-filter>
        </receiver>
    </application>

</manifest>

I modified the AppController class from here(http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/ ) to extend ParseApplication

public class AppController extends ParseApplication {
  
    public static final String TAG = AppController.class.getSimpleName();
 
    private RequestQueue mRequestQueue;
    private ImageLoader mImageLoader;
 
    private static AppController mInstance;
 
    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
    }
 
    public static synchronized AppController getInstance() {
        return mInstance;
    }
 
    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        }
 
        return mRequestQueue;
    }
 
    public ImageLoader getImageLoader() {
        getRequestQueue();
        if (mImageLoader == null) {
            mImageLoader = new ImageLoader(this.mRequestQueue,
                    new LruBitmapCache());
        }
        return this.mImageLoader;
    }
 
    public <T> void addToRequestQueue(Request<T> req, String tag) {
        // set the default tag if tag is empty
        req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
        getRequestQueue().add(req);
    }
 
    public <T> void addToRequestQueue(Request<T> req) {
        req.setTag(TAG);
        getRequestQueue().add(req);
    }
 
    public void cancelPendingRequests(Object tag) {
        if (mRequestQueue != null) {
            mRequestQueue.cancelAll(tag);
        }
    }
}

If you need more code please let me know.

log cat:
11-21 16:20:29.916: E/Trace(26640): error opening trace file: No such file or directory (2)
11-21 16:20:29.936: W/dalvikvm(26640): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
11-21 16:20:30.046: W/System.err(26640): Invalid int: ""
11-21 16:20:30.386: I/Adreno200-EGL(26640): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.01.21.010_msm8625_JB_REL_2.0.3_Merge_release_AU (Merge)
11-21 16:20:30.386: I/Adreno200-EGL(26640): Build Date: 10/26/12 Fri
11-21 16:20:30.386: I/Adreno200-EGL(26640): Local Branch: 
11-21 16:20:30.386: I/Adreno200-EGL(26640): Remote Branch: quic/jb_rel_2.0.3
11-21 16:20:30.386: I/Adreno200-EGL(26640): Local Patches: NONE
11-21 16:20:30.386: I/Adreno200-EGL(26640): Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.01.21.010 +  NOTHING
11-21 16:20:37.636: W/dalvikvm(26640): threadid=1: thread exiting with uncaught exception (group=0x40e08438)
11-21 16:20:49.016: E/Trace(26711): error opening trace file: No such file or directory (2)
11-21 16:20:49.036: W/dalvikvm(26711): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
11-21 16:20:49.096: W/System.err(26711): Invalid int: ""
Community
  • 1
  • 1
Steve Kamau
  • 2,755
  • 10
  • 42
  • 73
  • Add your logcat error! – Carnal Nov 21 '14 at 13:17
  • It may also be beneficial to add the exception from logcat. – Alexander Kohler Nov 21 '14 at 13:18
  • I have included log cat in my edit – Steve Kamau Nov 21 '14 at 13:22
  • androidhive samples are bad ... there is no need for extending Application class for using the volley ... class with static metods: `getImageLoader(Context appContext)` and `getRequestQueue(Context appContext)` should be enough – Selvin Nov 21 '14 at 13:28
  • From their sample tutorials they say:"The best way to maintain volley core objects and request queue is, making them global by creating a singleton class which extends Application object." – Steve Kamau Nov 21 '14 at 13:32
  • hehe thats why i wrote **androidhive samples are bad**. There is too many bad code practices there (and i'm not only talking about this sample but their samples at all) – Selvin Nov 21 '14 at 13:33
  • from documentation: `There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton.` – Selvin Nov 21 '14 at 13:37
  • @Selvin,i get you.What do you suggest i do to implement the above? – Steve Kamau Nov 21 '14 at 13:38
  • in the way as I stated in my previous comment ... – Selvin Nov 21 '14 at 13:39
  • Howcome you cannot have both Parse and Volley in the same Application class? As far as I know, Parse is just a few lines of initiation inside onCreate – cYrixmorten Nov 21 '14 at 13:46
  • @Selvin i'm getting error markers in the code.I am not implementing it in the right way.If you could refer me to somewhere i can check out more code i'd highly appreciate. – Steve Kamau Nov 21 '14 at 13:54
  • @cYrixmorten let me try that now.i see your point – Steve Kamau Nov 21 '14 at 13:56
  • @cYrixmorten It has worked.Thanks alot guys.Appreciate it much. – Steve Kamau Nov 21 '14 at 14:14

0 Answers0