Kurt
Kurt

Reputation: 777

Unable to call an activity using an intent

I am trying to call an activity from my mainactivity, but it is crashing an I cannot figure out why.

I call the activity from my mainactivity using a button as follows

btnStart.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, ShapeScreen.class);
            startActivity(i);   
    }
});

This then opens up an activity with code as follows, which should just bring up the layout shapesscreen.xml (which has no errors in it)

public class ShapeScreen extends Activity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.shapescreen);
   }
}

The second activity is defined in my manifest

<activity
    android:name=".MainActivity"
    android:label="Cubic Measurement" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".ShapeScreen"
    android:label="Cubic Measurement" >
    <intent-filter>
        <action android:name="kurt.steveboss.shapescreen" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

But when I click this button the app crashes and I get the following error in my LogCat

 01-02 15:03:37.550: I/InputReader(2100): Touch event's action is 0x1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=]
 01-02 15:03:37.550: I/InputDispatcher(2100): Delivering touch to current input target: action: 0x1
 01-02 15:03:37.550: I/InputDispatcher(2100): Delivering touch to current input target: action: 0x1
 01-02 15:03:37.550: I/InputDispatcher(2100): Delivering touch to current input target: action: 0x1
 01-02 15:03:37.555: I/ActivityManager(2100): START {intent.toShortString} from pid 8045
 01-02 15:03:37.555: I/power(2100): *** acquire_dvfs_lock : lockType : 1  freq : 1000000 
 01-02 15:03:37.555: D/PowerManagerService(2100): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1000000  uid : 1000  pid : 2100  tag : ActivityManager
 01-02 15:03:37.555: W/ActivityManager(2100): mDVFSLock.acquire()
 01-02 15:03:37.570: D/ActivityManager(2100): Trying to launch applicationName
 01-02 15:03:37.580: D/KeyguardViewMediator(2100): setHidden false
 01-02 15:03:37.650: D/dalvikvm(8045): GC_FOR_ALLOC freed 22K, 2% free 18560K/18887K, paused 10ms
 01-02 15:03:37.655: I/dalvikvm-heap(8045): Grow heap (frag case) to 21.095MB for 2903056-byte allocation
 01-02 15:03:37.680: D/dalvikvm(8045): GC_CONCURRENT freed 2K, 2% free 21393K/21767K, paused 1ms+1ms
 01-02 15:03:37.765: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 21394K/21767K, paused 9ms
 01-02 15:03:37.770: I/dalvikvm-heap(8045): Grow heap (frag case) to 23.864MB for 2903056-byte allocation
 01-02 15:03:37.790: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 24229K/24647K, paused 1ms+2ms
 01-02 15:03:37.875: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 24231K/24647K, paused 10ms
 01-02 15:03:37.880: I/dalvikvm-heap(8045): Grow heap (frag case) to 26.634MB for 2903056-byte allocation
 01-02 15:03:37.900: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 27066K/27527K, paused 2ms+2ms
 01-02 15:03:37.985: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 27067K/27527K, paused 9ms
 01-02 15:03:37.995: I/dalvikvm-heap(8045): Grow heap (frag case) to 29.404MB for 2903056-byte allocation
 01-02 15:03:38.015: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 29902K/30407K, paused 1ms+1ms
 01-02 15:03:38.095: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 29904K/30407K, paused 9ms
 01-02 15:03:38.105: I/dalvikvm-heap(8045): Grow heap (frag case) to 32.174MB for 2903056-byte allocation
 01-02 15:03:38.125: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 32739K/33287K, paused 1ms+1ms
 01-02 15:03:38.210: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 32741K/33287K, paused 10ms
 01-02 15:03:38.220: I/dalvikvm-heap(8045): Grow heap (frag case) to 34.944MB for 2903056-byte allocation
 01-02 15:03:38.235: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 35576K/36167K, paused 2ms+2ms
 01-02 15:03:38.315: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 35578K/36167K, paused 9ms
 01-02 15:03:38.325: I/dalvikvm-heap(8045): Grow heap (frag case) to 37.714MB for 2903056-byte allocation
 01-02 15:03:38.340: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 38413K/39047K, paused 2ms+2ms
 01-02 15:03:38.415: D/dalvikvm(8045): GC_FOR_ALLOC freed <1K, 2% free 38414K/39047K, paused 10ms
 01-02 15:03:38.430: I/dalvikvm-heap(8045): Grow heap (frag case) to 40.485MB for 2903056-byte allocation
 01-02 15:03:38.445: D/dalvikvm(8045): GC_CONCURRENT freed <1K, 2% free 41249K/41927K, paused 2ms+2ms
 01-02 15:03:38.555: I/power(2100): *** release_dvfs_lock : lockType : 1 
 01-02 15:03:38.555: D/PowerManagerService(2100): releaseDVFSLockLocked : all DVFS_MIN_LIMIT are released 
 01-02 15:03:38.555: W/ActivityManager(2100): mDVFSLock.release()
 01-02 15:03:38.975: W/PowerManagerService(2100): Timer 0x7->0x3|0x0
 01-02 15:03:38.975: I/PowerManagerService(2100): Ulight 0x7->0x3|0x0
 01-02 15:03:38.975: D/lights(2100): write_int /sys/class/sec/sec_touchkey/brightness = 2
 01-02 15:03:38.975: D/PowerManagerService(2100): setLightBrightness : mButtonLight : 0
 01-02 15:03:39.725: D/KeyguardViewMediator(2100): handleTimeout

Upvotes: 0

Views: 1294

Answers (3)

yogi
yogi

Reputation: 237

I think you didn't start a activity on your AndroidManifest.xml file in your application.You just try this code on your AndroidManifestfie

 <activity
 android:name=" .ShapeScreen" >
</activity>

now you can try this will work definitely

Upvotes: 1

Narendra Pal
Narendra Pal

Reputation: 6604

use this

@Override
            public void onClick(View v) {
                Intent i = new Intent("YOUR_ACTIVITY_CLASS.this,ShapeScreen.class");
                startActivity(i);   
            }

Instead of

 @Override
        public void onClick(View v) {
            Intent i = new Intent("kurt.steveboss.shapescreen");
            startActivity(i);   
        }

Upvotes: 1

A--C
A--C

Reputation: 36449

You should use the .class approach to launch your Actvity.

btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, ShapeScreen.class);
                startActivity(i);   
            }
        });

Upvotes: 2

Related Questions