• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Intent is not called from Parent Activity

SaiSuresh

Lurker
Sep 29, 2015
2
0
Dear Friends,

I am new to Android development. I have a problem that Intent is not started. I have created an Intent in a parent activity class trying to call the child Activity. The parent class is QuizActivity.java, calling CheatActivity.java. I get the following error. Could anyone help me what could be the issue please?
Please find below the LogCat & Class files along with manifest.xml file.
You help is deeply appreciated.

LogCat:
09-30 21:33:28.218 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v4.app.INotificationSideChannel$Stub$Proxy.cancel(java.lang.String, int, java.lang.String) took 110.328ms
09-30 21:33:28.410 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v4.app.ListFragment.ensureList() took 137.951ms
09-30 21:33:28.569 350-487/system_process I/ActivityManager﹕ Delay finish: com.android.email/.service.EmailBroadcastReceiver
09-30 21:33:31.870 350-643/system_process W/ActivityManager﹕ Unable to start service Intent { cmp=com.android.email/.service.AttachmentService } U=0: not found
09-30 21:33:32.464 67-67/? I/art﹕ Background concurrent mark sweep GC freed 779(32KB) AllocSpace objects, 0(0B) LOS objects, 82% free, 111KB/623KB, paused 1.528ms total 176.515ms
09-30 21:33:32.482 1059-1081/com.android.email I/Email﹕ Observing account changes for notifications
09-30 21:33:32.619 350-364/system_process I/ActivityManager﹕ Start proc com.android.exchange for service com.android.exchange/.service.EasService: pid=1082 uid=10027 gids={50027, 9997, 3003, 1028, 1015} abi=armeabi-v7a
09-30 21:33:32.659 350-643/system_process W/ActivityManager﹕ Unable to start service Intent { cmp=com.android.email/.service.AttachmentService } U=0: not found
09-30 21:33:33.473 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v4.widget.DrawerLayout.closeDrawers(boolean) took 874.601ms
09-30 21:33:34.308 350-635/system_process W/ActivityManager﹕ Unable to start service Intent { cmp=com.android.email/.service.AttachmentService } U=0: not found
09-30 21:33:34.572 350-364/system_process I/ActivityManager﹕ Resuming delayed broadcast
09-30 21:33:34.592 495-495/com.android.inputmethod.latin I/SystemBroadcastReceiver﹕ Boot has been completed
09-30 21:33:34.680 1059-1059/com.android.email E/ActivityThread﹕ Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@415a251 that was originally bound here
android.app.ServiceConnectionLeaked: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@415a251 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1070)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:964)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1768)
at android.app.ContextImpl.bindService(ContextImpl.java:1751)
at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:176)
at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:219)
at com.android.email.service.EmailServiceUtils.isServiceAvailable(EmailServiceUtils.java:160)
at com.android.email.provider.AccountReconciler.reconcileAccountsInternal(AccountReconciler.java:164)
at com.android.email.provider.AccountReconciler.reconcileAccounts(AccountReconciler.java:113)
at com.android.email.service.EmailBroadcastProcessorService.reconcileAndStartServices(EmailBroadcastProcessorService.java:305)
at com.android.email.service.EmailBroadcastProcessorService.onBootCompleted(EmailBroadcastProcessorService.java:295)
at com.android.email.service.EmailBroadcastProcessorService.onHandleIntent(EmailBroadcastProcessorService.java:130)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
09-30 21:33:34.645 1031-1053/com.android.calendar D/InitAlarmsService﹕ Clearing and rescheduling alarms.
09-30 21:33:34.747 1059-1059/com.android.email E/StrictMode﹕ null
android.app.ServiceConnectionLeaked: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@415a251 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1070)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:964)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1768)
at android.app.ContextImpl.bindService(ContextImpl.java:1751)
at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:176)
at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:219)
at com.android.email.service.EmailServiceUtils.isServiceAvailable(EmailServiceUtils.java:160)
at com.android.email.provider.AccountReconciler.reconcileAccountsInternal(AccountReconciler.java:164)
at com.android.email.provider.AccountReconciler.reconcileAccounts(AccountReconciler.java:113)
at com.android.email.service.EmailBroadcastProcessorService.reconcileAndStartServices(EmailBroadcastProcessorService.java:305)
at com.android.email.service.EmailBroadcastProcessorService.onBootCompleted(EmailBroadcastProcessorService.java:295)
at com.android.email.service.EmailBroadcastProcessorService.onHandleIntent(EmailBroadcastProcessorService.java:130)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
09-30 21:33:34.809 1000-1000/? W/dex2oat﹕ Compilation of boolean android.support.v4.widget.ListViewAutoScrollHelper.canTargetScrollVertically(int) took 105.297ms
09-30 21:33:34.878 495-495/com.android.inputmethod.latin I/LauncherIconVisibilityManager﹕ Activity has already been disabled: ComponentInfo{com.android.inputmethod.latin/com.android.inputmethod.latin.setup.SetupActivity}
09-30 21:33:35.247 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v4.widget.ScrollerCompat$ScrollerCompatImplBase.abortAnimation(java.lang.Object) took 332.651ms
09-30 21:33:35.398 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v4.widget.ScrollerCompat$ScrollerCompatImplBase.fling(java.lang.Object, int, int, int, int, int, int, int, int, int, int) took 142.944ms
09-30 21:33:35.581 1000-1000/? W/dex2oat﹕ Compilation of int android.support.v4.widget.ScrollerCompat$ScrollerCompatImplBase.getFinalY(java.lang.Object) took 176.451ms
09-30 21:33:35.886 703-703/com.android.deskclock V/AlarmClock﹕ AlarmInitReceiver android.intent.action.TIME_SET
09-30 21:33:36.365 703-1056/com.android.deskclock V/AlarmClock﹕ AlarmInitReceiver finished
09-30 21:33:36.556 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v7.app.ActionBarActivity.addContentView(android.view.View, android.view.ViewGroup$LayoutParams) took 111.782ms
09-30 21:33:36.717 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v7.app.ActionBarActivity.onConfigurationChanged(android.content.res.Configuration) took 102.255ms
09-30 21:33:36.837 1000-1000/? W/dex2oat﹕ Compilation of void android.support.v7.app.ActionBarActivity.onCreateSupportNavigateUpTaskStack(android.support.v4.app.TaskStackBuilder) took 111.984ms
09-30 21:33:36.856 1031-1031/com.android.calendar D/AlertReceiver﹕ onReceive: a=android.intent.action.PROVIDER_CHANGED Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar flg=0x10 cmp=com.android.calendar/.alerts.AlertReceiver }
09-30 21:33:36.919 350-645/system_process I/ActivityManager﹕ Delay finish: com.android.calendar/.alerts.AlertReceiver
09-30 21:33:37.021 1000-1000/? W/dex2oat﹕ Compilation of boolean android.support.v7.app.ActionBarActivity.onMenuItemSelected(int, android.view.MenuItem) took 177.713ms
09-30 21:33:37.058 1031-1104/com.android.calendar D/AlertService﹕ 0 Action = android.intent.action.PROVIDER_CHANGED

QuizActivity.java(Parent):
====================
package com.application.suresh.geoquiz;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;


public class QuizActivity extends ActionBarActivity {

private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private Button mCheatButton;
private TextView mQuestionTextView;
private static final String TAG="QuizActivity";
private boolean mIsCheater;

private TrueFalse[] mQuestionBank=new TrueFalse[] {
new TrueFalse(R.string.question_telugu_grosser,true),
new TrueFalse(R.string.question_mba_need,false),
new TrueFalse(R.string.question_health,true),
new TrueFalse(R.string.question_entrepreneur,true),
};

private int mCurrentIndex=0;

private void updateQuestion(){
int question=mQuestionBank[mCurrentIndex].getQuestion();
mQuestionTextView.setText(question);
}

private void checkAnswer(boolean userPressedTrue){
boolean answerIsTrue=mQuestionBank[mCurrentIndex].isTrueQuestion();

int messageReadId=0;
if (mIsCheater){
messageReadId=R.string.judgment_toast;
}else {
if (userPressedTrue = answerIsTrue) {
messageReadId = R.string.correct_toast;
} else {
messageReadId = R.string.incorrect_toast;
}
}

Toast.makeText(this,messageReadId,Toast.LENGTH_SHORT).show();
}


@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"onCreate called");
setContentView(R.layout.activity_quiz);

mQuestionTextView = (TextView)findViewById(R.id.question_text_view);


mTrueButton=(Button)findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new View.OnClickListener(){
@override
public void onClick(View v){
//Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
checkAnswer(true);
}
});

mNextButton=(Button)findViewById(R.id.next_button);
mNextButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
mCurrentIndex=(mCurrentIndex+1) % mQuestionBank.length;
mIsCheater=false;
updateQuestion();
}
});

mCheatButton=(Button)findViewById(R.id.cheat_button);
mCheatButton.setOnClickListener(new View.OnClickListener(){
@override
public void onClick(View v){
//Start Cheat Activity
Intent i=new Intent(QuizActivity.this, CheatActivity.class);
// startActivity(i);

boolean answerIsTrue=mQuestionBank[mCurrentIndex].isTrueQuestion();
i.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE,answerIsTrue);
startActivityForResult(i,0);
}
});
updateQuestion();
mFalseButton=(Button)findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
//Toast.makeText(QuizActivity.this,R.string.correct_toast,Toast.LENGTH_SHORT).show();
checkAnswer(false);
}
});



}
@override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (data == null){
return;
}
mIsCheater=data.getBooleanExtra(CheatActivity.EXTRA_ANSWER_SHOWN,false);
}


@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_quiz, 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);
}

@override
public void onStart() {
super.onStart();
Log.d(TAG,"onStart() called");
}

@override
public void onPause(){
super.onPause();
Log.d(TAG,"onPause() called");
}

@override
public void onResume(){
super.onResume();
Log.d(TAG,"onResume() called");
}

@override
public void onStop(){
super.onStop();
Log.d(TAG,"onStop() called");
}

@override
public void onDestroy(){
super.onDestroy();
Log.d(TAG,"onDestroy() called");
}
}


CheatActivity.java(Child):
=========================
package com.application.suresh.geoquiz;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
* Created by suresh on 27-09-2015.
*/
public class CheatActivity extends ActionBarActivity{

public static final String EXTRA_ANSWER_IS_TRUE="com.application.suresh.geoquiz.answer_is_true";
public static final String EXTRA_ANSWER_SHOWN="com.application.suresh.geoquiz.answer_shown";
private boolean mAnswerIsTrue;
private TextView mAnswerTextView;
private Button mShowAnswer;

private void setAnswerShownResult(boolean isAnswerShown){
Intent data = new Intent();
data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown);
setResult(RESULT_OK,data);
}
//@override
protected void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cheat);

mAnswerIsTrue=getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE,false);
mAnswerTextView=(TextView)findViewById(R.id.answerTextView);

mShowAnswer=(Button)findViewById(R.id.showAnswerButton);
setAnswerShownResult(false);

mShowAnswer.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
if (mAnswerIsTrue){
mAnswerTextView.setText(R.string.true_button);
}else{
mAnswerTextView.setText(R.string.false_button);
}
setAnswerShownResult(true);
}

});
}
}

AndroidManifest.xml:
====================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.suresh.geoquiz" >

<application
android:allowBackup="true"
android:icon="@Mipmap/ic_launcher"
android:label="@String/app_name"
android:theme="@Style/AppTheme" >
<activity
android:name=".QuizActivity"
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
android:name=".CheatActivity"
android:label="@String/app_name" />
</application>

</manifest>
 
Hi. am Interested to know to which new forum this post is moved ?coz I wanted to know the no. of views as if anybody got a chance to see my Query?
It was moved to the Application Development subforum, one of the few corners of the site dedicated to development-related discussion. All other areas of the site are really more for users rather than developers, so you're more likely to get help here. :)
 
Upvote 0
Hi. am Interested to know to which new forum this post is moved ?coz I wanted to know the no. of views as if anybody got a chance to see my Query?

Moves are a little confusing (the first time). You posted the message in the thread in the new location. If you scroll to the top of the page you will see the exact location of the forum in the overall structure.

Good luck.

... Thom
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones