glUtilsParamSize error when opening new activity - java

I have one problem. When i run my app, i want to open new activity with button. That works with one activity,but the other activity(two buttons in main menu,one works other not) just closes the app. Here is the code of that activity,and the logcat of errors. Logcat says there is problem with glutilsparamsize
My problem is that it doesn't want to open activity pronadi. My buttons Opis and Izlaz work and they open activity opis and izlaz button exits,but button pronadi says "com.example.shromid. stopped" and closes the app. I want to open activity pronadi.
LOGCAT errors
01-31 09:49:47.351 4576-4596/com.example.shromid E/eglCodecCommon:
glUtilsParamSize: unknow param 0x00008cdf
01-31 09:49:47.352 4576-4596/com.example.shromid E/eglCodecCommon:
glUtilsParamSize: unknow param 0x00008cdf
01-31 09:49:47.360 4576-4596/com.example.shromid E/eglCodecCommon:
glUtilsParamSize: unknow param 0x00008824
01-31 09:49:47.360 4576-4596/com.example.shromid E/eglCodecCommon:
glUtilsParamSize: unknow param 0x00008824
Activity that i want to open
package com.example.shromid;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class Pronadi extends Activity {
Spinner kboja;
Spinner ktekstura;
Spinner koblik;
ArrayAdapter<String> adapter;
ArrayAdapter<String> adapter1;
ArrayAdapter<String> adapter2;
DatabaseHelper db;
List<String>gljive=new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pronadi);
kboja = (Spinner) findViewById(R.id.kboja);
ktekstura = (Spinner) findViewById(R.id.ktekstura);
koblik = (Spinner) findViewById(R.id.koblik);
db = new DatabaseHelper(Pronadi.this);
prepareData();
prepareData1();
prepareData2();
kboja.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), "" + parent.getItemAtPosition(position).toString(), Toast.LENGTH_SHORT);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
koblik.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),""+parent.getItemAtPosition(position).toString(),Toast.LENGTH_SHORT);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
ktekstura.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),""+parent.getItemAtPosition(position).toString(),Toast.LENGTH_SHORT);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public void prepareData() {
gljive=db.getKlobuk_Boja();
adapter=new ArrayAdapter<String>(Pronadi.this,android.R.layout.simple_spinner_dropdown_item,android.R.id.text1,gljive);
kboja.setAdapter(adapter);
}
public void prepareData1() {
gljive=db.getKlobuk_Oblik();
adapter1=new ArrayAdapter<String>(Pronadi.this,android.R.layout.simple_spinner_dropdown_item,android.R.id.text1,gljive);
koblik.setAdapter(adapter1);
}
public void prepareData2(){
gljive=db.getKlobuk_Tekstura();
adapter2=new ArrayAdapter<String>(Pronadi.this,android.R.layout.simple_spinner_dropdown_item,android.R.id.text1,gljive);
ktekstura.setAdapter(adapter2);
}
}
Activity with buttons to open activity
package com.example.shromid;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
izlaz();
otvoriopis();
otvoripronadi();
}
public Button btnopis;
public void otvoriopis(){
btnopis=(Button)findViewById(R.id.btnopis);
btnopis.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent otvoriopis= new Intent(MainActivity.this,Opis.class);
startActivity(otvoriopis);
}
});
}
public Button btnpronadi;
public void otvoripronadi(){
btnpronadi=(Button)findViewById(R.id.btnpronadi);
btnpronadi.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent otvoripronadi= new Intent(MainActivity.this,Pronadi.class);
startActivity(otvoripronadi);
}
});
}
public Button btnizlaz;
public void izlaz(){
btnizlaz=(Button)findViewById(R.id.btnizlaz);
btnizlaz.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
}
android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shromid">
<application
android:allowBackup="true"
android:icon="#mipmap/app_ikona"
android:roundIcon="#mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashScreen"
android:label="ShromID"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".Opis" />
<activity android:name=".Pronadi"></activity>
</application>
</manifest>
Main activity xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pozadina2"
android:orientation="vertical"
tools:context="com.example.shromid.MainActivity">
<!-- Gumbovi u glavnom meniju -->
<Button
android:id="#+id/btnpronadi"
android:layout_width="183dp"
android:layout_height="56dp"
android:layout_marginBottom="11dp"
android:background="#drawable/gumbpronadi"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/btnopis"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView3" />
<Button
android:id="#+id/btnopis"
android:layout_width="183dp"
android:layout_height="56dp"
android:layout_marginBottom="11dp"
android:background="#drawable/gumbopis"
app:layout_constraintBottom_toTopOf="#+id/btnizlaz"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnpronadi" />
<Button
android:id="#+id/btnizlaz"
android:layout_width="183dp"
android:layout_height="56dp"
android:layout_marginBottom="106dp"
android:background="#drawable/gumbizlaz"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnopis" />
<!-- Kraj gumbova u glavnom meniju -->
<!-- Logo u glavnom meniju -->
<ImageView
android:id="#+id/imageView3"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="4dp"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="16dp"
android:src="#drawable/gljiveprobna"
app:layout_constraintBottom_toTopOf="#+id/btnpronadi"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" android:contentDescription="#string/todo" />
</android.support.constraint.ConstraintLayout>

Related

App working on Nougat+ versions but crashing on Marshmallow and Lollipop

This is the error report whenever I launch the app it crashes and says
Unfortunately, {app-name} has stopped
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2413)
at android.app.ActivityThread.access$800 (ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1317)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:135)
at android.app.ActivityThread.main (ActivityThread.java:5343)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:700)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:806)
at android.view.LayoutInflater.inflate (LayoutInflater.java:504)
at android.view.LayoutInflater.inflate (LayoutInflater.java:414)
at android.view.LayoutInflater.inflate (LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:139)
at com.khokhar.yousaf.cipher.Splash.onCreate (Splash.java:15)
at android.app.Activity.performCreate (Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2292)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawableForCookie (Resources.java:2444)
at android.content.res.Resources.loadDrawable (Resources.java:2384)
at android.content.res.TypedArray.getDrawable (TypedArray.java:749)
at android.view.View.<init> (View.java:3742)
at android.widget.ImageView.<init> (ImageView.java:149)
at android.widget.ImageView.<init> (ImageView.java:145)
at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:71)
at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:67)
at android.support.v7.app.AppCompatViewInflater.createImageView (AppCompatViewInflater.java:181)
at android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:105)
at android.support.v7.app.AppCompatDelegateImplV9.createView (AppCompatDelegateImplV9.java:1035)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView (AppCompatDelegateImplV9.java:1092)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:725)
This is my Splash Screen coding
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Window;
public class Splash extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_splash);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//thread for splash screen running
Thread logoTimer = new Thread() {
public void run() {
try {
sleep(2500);
} catch (InterruptedException e) {
Log.d("Exception", "Exception" + e);
} finally {
startActivity(new Intent(Splash.this, MainActivity.class));
}
finish();
}
};
logoTimer.start();
}
}
And this XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/splashScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/colorPrimary"
android:orientation="vertical"
tools:context="com.khokhar.yousaf.cipher.Splash">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher_foreground"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/mediumload" />
</RelativeLayout>
The drawable image I used is 600x1024 PNG
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.khokhar.yousaf.cipher">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:hardwareAccelerated="true"
android:icon="#drawable/cee"
android:label="#string/app_name"
android:roundIcon="#drawable/cee"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "java-lang-programming://android-app-google-plus-demo"-->
<data
android:host="cipherengineers"
android:scheme="android-app-cipher-engineers" />
</intent-filter>
</activity>
<activity android:name=".Splash"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
My MainActivity is basically webview
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
ProgressBar progressBar;
WebView webView;
String url="https://website/";
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
webView = (WebView) findViewById(R.id.webView);
textView = (TextView) findViewById(R.id.textView1212);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
textView.setText(progress + "");
}
#Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
WebView newWebView = new WebView(MainActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setSupportZoom(true);
newWebView.getSettings().setBuiltInZoomControls(true);
newWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
newWebView.getSettings().setSupportMultipleWindows(true);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
return true;
}
});
webView.setWebViewClient(new MyWebViewClient());
WebSettings browserSetting = webView.getSettings();
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
browserSetting.setJavaScriptCanOpenWindowsAutomatically(true);
browserSetting.setJavaScriptEnabled(true);
browserSetting.setLoadWithOverviewMode(true);
browserSetting.setSupportMultipleWindows(true);
browserSetting.setDatabaseEnabled(true);
browserSetting.setAppCacheEnabled(true);
browserSetting.setDomStorageEnabled(true);
browserSetting.setDomStorageEnabled(true);
browserSetting.setGeolocationEnabled(true);
browserSetting.setSaveFormData(false);
browserSetting.setUseWideViewPort(true);
browserSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
browserSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
browserSetting.setDomStorageEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}else {
CookieManager.getInstance().setAcceptCookie(true);
}
webView.loadUrl(url);
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.setVisibility(View.INVISIBLE);
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
public void onBackPressed() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this);
// set title
alertDialogBuilder.setTitle("Exit");
// set dialog message
alertDialogBuilder
.setMessage("Are You Sure?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.GRAY));
}
}
I removed background from Splash Screen XML and nothing worked
MainActivity XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/loading_screen"
android:orientation="vertical"
tools:context="com.khokhar.yousaf.cipher.MainActivity">
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="218dp"
android:progressTint="?android:attr/fastScrollTextColor"
android:visibility="invisible" />
<TextView
android:id="#+id/textView1212"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="23dp"
android:textColor="#android:color/holo_red_dark"
android:textSize="13sp"
android:textStyle="bold|italic" />
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:animationCache="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="41dp" />
</RelativeLayout>
I can't figure it out.
Removing the background from ImageView
The reason is lower versions are not able to find ic_launcher_foreground in the drawable directory which actually exists in drawable-v24.
Remove the background image and write your ImageView like this
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/mediumload" />
you cant start a new Activity on Background Thread.. since you run new Thread and inside you start a new Activity it will crash..
2 solutions : declare Handler outside the Thread
Handler handler = new Handler();
inside the thread run
handler.post(new Runnable() { public void run() { startActivity(..) } });
or use function :
RunOnUiThread(new Runnable() { public void run() { startActivity(...) } );

xml layout crashes on loading for android app

enter image description hereHey guys I'm at the end of my Java 1 class working on my project. We are making a memory/concentration game. My issue is that when I click the easy button for the next activity the app crashes. I have tried using fragments and activities and just can't seem to get it right. I have also tried using the layout I need on my main activity just to see if I could get it to display. Even then it just crashes on startup of the app. Any help would be appreciated.
Startup Screen activity.
package com.bignerdranch.android.memory;
import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
public class MemoryActivity extends Activity {
private Button mEasy;
private Button mMedium;
private Button mHard;
private CheckBox mSilence;
public MediaPlayer player;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_memory);
player = new MediaPlayer();
player = MediaPlayer.create(this, R.raw.mkstartmusic);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setLooping(true);
player.start();
mEasy = (Button)findViewById(R.id.easy);
mEasy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent easy = new Intent(getApplicationContext(), EasyGame.class);
startActivity(easy);
}
});
mMedium = (Button)findViewById(R.id.medium);
mMedium.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
mHard = (Button)findViewById(R.id.hard);
mHard.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
mSilence = (CheckBox)findViewById(R.id.silence);
mSilence.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(mSilence.isChecked()) {
player.pause();
} else if(mSilence.isChecked() == false) {
player.start();
}
}
});
}
#Override
protected void onStop() {
super.onPause();
if (player != null){
player.stop();
if (isFinishing()){
player.stop();
player.release();
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.activity_memory, menu);
return true;
}
}
Second Activity (Easy option)
package com.bignerdranch.android.memory;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
public class EasyGame extends Activity {
private ImageButton buttOne;
private ImageButton buttTwo;
private ImageButton buttThree;
private ImageButton buttFour;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_easy);
buttOne = (ImageButton)findViewById(R.id.ImageButton01);
buttOne.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
buttTwo = (ImageButton)findViewById(R.id.ImageButton02);
buttTwo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
buttThree = (ImageButton)findViewById(R.id.ImageButton03);
buttThree.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
buttFour = (ImageButton)findViewById(R.id.ImageButton04);
buttFour.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.activity_easy, menu);
return true;
}
}
This is the layout for the Easy option
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/easyback"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#drawable/easyback"
android:clickable="false"
android:duplicateParentState="false"
android:longClickable="false"
android:scaleType="centerCrop" />
<ImageButton
android:id="#+id/ImageButton04"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_below="#+id/ImageButton01"
android:layout_toRightOf="#+id/ImageButton01"
android:layout_toEndOf="#+id/ImageButton01"
android:maxHeight="25dp"
android:maxWidth="25dp"
android:scaleType="fitXY"
android:src="#drawable/dragonemb" />
<ImageButton
android:id="#+id/ImageButton02"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_above="#+id/ImageButton04"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="22dp"
android:layout_marginEnd="22dp"
android:maxHeight="25dp"
android:maxWidth="25dp"
android:scaleType="fitXY"
android:src="#drawable/dragonemb" />
<ImageButton
android:id="#+id/ImageButton03"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignTop="#+id/ImageButton04"
android:layout_toLeftOf="#+id/ImageButton04"
android:layout_toStartOf="#+id/ImageButton04"
android:maxHeight="25dp"
android:maxWidth="25dp"
android:scaleType="fitXY"
android:src="#drawable/dragonemb" />
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_marginTop="152dp"
android:layout_toLeftOf="#+id/ImageButton02"
android:maxHeight="25dp"
android:maxWidth="25dp"
android:scaleType="fitXY"
android:src="#drawable/dragonemb" />
</RelativeLayout>
OK It's not the full crash log you posted but at the top of it I saw roidManifest.xml?. And It's sure that you didn't defined your EasyGame Activity in your androidmanifest.xml so add this line inside application tag,
<manifest package="com....." . . . >
<application . . . >
<activity
android:name=".EasyGame"
android:label="easygame">
</activity>
. . .
</application>
</manifest>
In addition you are trying to cast your ImageButton into Button consider fixing that as well.
Add code below to AndroidManfest
<activity
android:name=".EasyGame"
/>
its simple just add this line to your AndroidManifest
<activity android:name="Activity"/>
The logcat did mentioned that you need to declare your activity within the Android Manifest which you didn't. please read the logcat carefully as it really helps to find what went wrong.
OK, so I had tried all of your guys suggestions which I had were part of the issue, the final issue turned out to that I needed to add my images to the drawable-xhdpi. Thanks for all your help.

OnPause() and also onDestroy() never called when other activity opened

I have an app with many activities using intent. I have a sharedPreferences method for saving values.
I have a welcome screen that I set to display when the app launches (onCreate is called). In the same activity, I delete the sharePreferences method so when I reopen the app the welcome screen will launch again.
The problem is, when I change to another activity and back again to the main activity and press the exit button. When I launch the app again, it does not show the welcome screen. I think, the main activity is still running so, onPause(), onStop() and onDestroy() are never called. When I stay in the same activity (main) and press exit, it will call onDestroy() (that contains the erase sharedPreferences method).
I didn't set the finish() method. If I set that, every moved activity will call onDestroy in Main activity so the welcome screen will launch every move to that activity.
My mainactivity.java
package com.bani.latihan;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
public class Main extends AppCompatActivity {
RelativeLayout PopupScreen, layoutAsli;
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
#Override
public void onDestroy(){
super.onDestroy();
SharedPreferences settings = getSharedPreferences("PreferencesWelcome", Context.MODE_PRIVATE);
settings.edit().remove("ditekan").apply();
}
#Override
public void onCreate(Bundle savedInstanceState) {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
setContentView(R.layout.main);
Button btn1 =(Button)findViewById(R.id.button1);
final Button btn2 =(Button)findViewById(R.id.button2);
PopupScreen = (RelativeLayout)findViewById(R.id.PopupScreen);
layoutAsli = (RelativeLayout)findViewById(R.id.layoutAsli);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent2 = new Intent(Main.this, Intent2.class);
startActivity(intent2);
}
});
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
moveTaskToBack(true);
finish();
}
});
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Isi dewek cuk!", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
EditText tvText = (EditText) findViewById(R.id.editText1);
SharedPreferences prefs = getSharedPreferences("Preferences", Context.MODE_PRIVATE);
if (prefs.contains("text")){
tvText .setText(prefs.getString("text", ""));
}
SharedPreferences prefs2 = getSharedPreferences("PreferencesWelcome", Context.MODE_PRIVATE);
if (prefs2.contains("ditekan")){
PopupScreen.setVisibility(View.INVISIBLE);
layoutAsli.setVisibility(View.VISIBLE);
}
}
public void dismisWelcomeMessageBox(View view) {
PopupScreen.setVisibility(View.INVISIBLE);
layoutAsli.setVisibility(View.VISIBLE);
}
#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_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);
}
#Override
public void onPause() {
super.onPause();
EditText tvText = (EditText) findViewById(R.id.editText1);
Button btWelcome = (Button) findViewById(R.id.button_welcome);
SharedPreferences.Editor prefEditor = getSharedPreferences("Preferences", Context.MODE_PRIVATE).edit();
SharedPreferences.Editor prefEditor2 = getSharedPreferences("PreferencesWelcome", Context.MODE_PRIVATE).edit();
prefEditor.putString("text", tvText.getText().toString());
prefEditor2.putBoolean("ditekan", btWelcome.isPressed());
prefEditor.apply();
prefEditor2.apply();
}
}
My another activity code:
package com.bani.latihan;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
/**
* Created by Bani Burhanuddin on 21/02/2016.
*/
public class Intent2 extends AppCompatActivity {
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
setContentView(R.layout.intent);
Button btnnext = (Button) findViewById(R.id.button5);
Button btnhome = (Button) findViewById(R.id.button6);
Button btnback = (Button) findViewById(R.id.button7);
btnnext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Intent2.this, Intent3.class));
finish();
}
});
btnhome.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Intent2.this, Main.class));
finish();
}
});
btnback.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Intent2.this, Main.class));
finish();
}
});
CompoundButton toggle = (CompoundButton) findViewById(R.id.switch1);
final ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
imageView2.setVisibility(View.GONE);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
imageView2.setVisibility(View.VISIBLE);
} else {
imageView2.setVisibility(View.GONE);
}
}
});
SharedPreferences prefs = getSharedPreferences("Preferences2", Context.MODE_PRIVATE);
if (prefs.contains("text2")) {
toggle.setChecked(prefs.getBoolean("text2", true));
}
}
#Override
public void onPause() {
super.onPause();
CompoundButton toggle = (CompoundButton) findViewById(R.id.switch1);
if (toggle.isChecked()) {
SharedPreferences.Editor editor = getSharedPreferences("Preferences2", MODE_PRIVATE).edit();
editor.putBoolean("text2", true);
editor.apply();
} else {
SharedPreferences.Editor editor = getSharedPreferences("Preferences2", MODE_PRIVATE).edit();
editor.putBoolean("text2", false);
editor.apply();
}
}
}
My Manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- Splash screen -->
<activity
android:name="com.bani.latihan.splashscreen"
android:label="#string/app_name"
android:screenOrientation="sensor"
android:configChanges="keyboardHidden|orientation|screenSize"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main activity -->
<activity
android:name="com.bani.latihan.Main"
android:screenOrientation="sensor"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<!-- Intent2 activity -->
<activity
android:name=".Intent2"
android:screenOrientation="sensor"
android:noHistory="true"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<!-- Intent3 activity -->
<activity
android:name=".Intent3"
android:screenOrientation="sensor"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<!-- Intent4 activity -->
<activity
android:name=".Intent4"
android:screenOrientation="sensor"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
</application>
</manifest>
My main layout
<RelativeLayout
android:id="#+id/PopupScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#123456"
android:orientation="vertical"
android:layout_margin="16dp"
android:padding="16dp"
android:visibility="visible">
<TextView
android:id="#+id/welcome_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:text="#string/welcome"
android:textColor="#ddd333"
android:textSize="28sp"
android:textStyle="bold" />
<TextView
android:id="#+id/welcome_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome_title"
android:text="#string/welcome_message"
android:textColor="#0dff00"
android:textSize="18sp" />
<Button
android:layout_width="wrap_content"
android:id="#+id/button_welcome"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom"
android:background="#3b978d"
android:onClick="dismisWelcomeMessageBox"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="#string/ok"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutAsli"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/hello_world"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText1"
android:layout_below="#+id/hello_world"/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:src="#drawable/imageview"
android:layout_gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/button1"
android:layout_marginTop="111dp"
android:layout_centerHorizontal="true"
android:layout_gravity="left|bottom" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:id="#+id/button2"
android:layout_below="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="59dp"
android:layout_gravity="right|bottom" />
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
I got ur problem. Currently u are using the MoveTaskToBack . It will not destroy the activity ,it just move back in ativity stack after that u finish
activity. So its not calling other callback methods. It always call onDestroy
Use either moveTasktoBack or finish. Dont use both, it will confusing.

Why is the set of listeners empty when I need them to be notified? (in an Android app)

In my Android app I have three classes, one is the MainActivity another one is called CustomerTransaction, which is just a Java class. There is also another activity called DataActivity which starts when the button Enter Data on the MainActivity screen is clicked. The activity DataActivity allows the user to enter a number in an EditText and then click the Send button to trigger a method in CustomerTransaction. I shall add the complete code below. But first let me explain my problem. In CustomerTransaction I have a method that provides values for two variables: totalAmount and transactionType (both are int). This values are needed in the MainActivity to be displayed on the main screen, when they are available. The MainActivity implements an interface called CustomListeners containing the header of the function that displays the two values (in TextViews). The values are communicated from CustomerTransaction to the method in MainActivity by notifying the listener when the values are available. The problem is that when I have the values, the set of listeners is empty. I would like to understand why this happens and then to correct the code.
Here's the code:
package com.example.customlistenertest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements CustomListeners {
TextView tv_amount;
TextView tv_transactionType;
Button btn_enterData;
CustomerTransaction control= new CustomerTransaction();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
control.registerListener(this);
tv_amount = (TextView) findViewById(R.id.textView_amount);
tv_transactionType = (TextView) findViewById(R.id.textView_transactionType);
btn_enterData = (Button) findViewById(R.id.button_enterData);
addListenerOnButtonEnterData();
}
public void addListenerOnButtonEnterData() {
btn_enterData.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent =
new Intent(MainActivity.this,com.example.customlistenertest.DataActivity.class);
startActivity(intent);
}
});
}
public void updateTotal(final int transactionType, final int totalAmount) {
runOnUiThread(new Runnable() {
public void run() {
tv_amount.setText(Integer.toString(totalAmount));
tv_transactionType.setText(Integer.toString(transactionType));
}});
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onResume(){
super.onResume();
control.registerListener(this);
}
#Override
protected void onPause() {
super.onPause();
}
#Override
protected void onDestroy() {
super.onDestroy();
control.unregisterListener(this);
}
} // End MainActivity
Following is the code for the DataActivity class:
package com.example.customlistenertest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class DataActivity extends Activity {
TextView tv_enterNumber;
EditText et_number;
Button btn_send;
CustomerTransaction transaction;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.enter_data);
btn_send = (Button) findViewById(R.id.button_send);
et_number = (EditText) findViewById(R.id.editText_number);
}
public void send(View view) {
transaction = new CustomerTransaction();
transComplete();
}
private void transComplete() {
new Thread("TransComplete") {
public void run() {
String s_number = et_number.getText().toString();
int value = Integer.parseInt(s_number);
transaction.setState(5, value);
finish();
}
}.start();
}
} // end DataActivity
Following is the code for the CustomerTransaction class:
package com.example.customlistenertest;
import java.util.HashSet;
import java.util.Set;
public class CustomerTransaction {
public static final int DATA_ENTERED = 1;
public static final int TRANSACTION_COMPLETE = 5;
private int state;
private int totalAmount;
private int transactionType;
public Set<CustomListeners> listeners = new HashSet<CustomListeners>();
public synchronized void registerListener(CustomListeners listener) {
listeners.add(listener);
}
public synchronized void unregisterListener(CustomListeners listener) {
listeners.remove(listener);
}
public synchronized void notifyListeners() {
for(CustomListeners listener : listeners) {
if (totalAmount != 0)
listener.updateTotal(transactionType,totalAmount);
else
listener.updateTotal(transactionType,0);
}
}
public void performOperation() {
new Thread("MyThread") {
public void run() {
notifyListeners();
}
}.start();
}
public void setState(final int state, final int value) {
this.state = state;
this.totalAmount = value;
this.transactionType = 999;
if (state == DATA_ENTERED) {
}
if (state == TRANSACTION_COMPLETE) {
performOperation();
}
}
} // end CustomerTransactionjava
I shall add the two layout files as well. The first is activity_main.xml:
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView_transactionType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button_enterData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Data" />
</LinearLayout>
The next one is the file enter_data.xml:
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView_enterNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter a number:" />
<EditText
android:id="#+id/editText_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="send"
android:text="Send" />
</LinearLayout>
Finally, here's the Manifest file.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.customlistenertest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:theme="#style/AppTheme"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity android:label="#string/app_name" android:name="MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.customlistenertest.DataActivity" >
</activity>
</application>
</manifest>
The "CustomerTransaction transaction" used in the MainActivity is not the same instance of the "CustomerTransaction transaction" of the one defined in the DataActivity. That explains why the DataActivity one is empty, because you did subscribe only with the one from the MainActivity. Two possible solutions for the problem:
Make the 'control' a singleton, so that you will be sure that there is only one instance of it at a time.
Make the 'listeners' variables and the 'register/unregister/notitifylisteners' methods static.
I prefer the option 1, but you can choose what you think it's best.
Good luck!

how to move from my MyAcctivity.java (login page) to HomeActivity.java (home page) with a click of button- INTELLIJ

It doesnt have any errors ..when i run on my emulator it UNFORTUNATELY STOPS
i am trying to make my button when i click it takes me to the next page....kindly help!
Here is codes for MyActivity.java
package com.example.INIKO_EVENTS;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
Button login;
Button sign_up;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
login=(Button)findViewById(R.id.Button15);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MyActivity.this,HomeActivity.class);
MyActivity.this.
startActivity(i);
}
});
sign_up=(Button)findViewById(R.id.signUpButton);
sign_up.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MyActivity.this,SignUpActivity.class);
MyActivity.this.
startActivity(i);
}
});
}
}
and heres my HomeActivity.java - it has buttons linking to other pages
package com.example.INIKO_EVENTS;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class HomeActivity extends Activity {
/**
* Created by eddie kamau on 2/14/14.
*/
Button button2;
Button button3;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
button2 = (Button)findViewById(R.id.toEventButton);
button2.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0) {
Intent i = new Intent(HomeActivity.this,EventActivity.class);
HomeActivity.this.
startActivity(i);
}
});
button3=(Button)findViewById(R.id.manage_your_guestButton2);
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(HomeActivity.this,GuestActivity.class);
HomeActivity.this.
startActivity(i);
}
});
}
}
main.xml
<Button
android:layout_width="141dp"
android:layout_height="wrap_content"
android:text="#string/login"
android:layout_margin="10sp"
android:id="#+id/Button15"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:onClick="onClick"/>
<Button
android:layout_width="121dp"
android:layout_height="wrap_content"
android:text="#string/sign_up"
android:id="#+id/signUpButton"
android:layout_gravity="center_horizontal"
android:maxWidth="600dp"
android:clickable="true"
android:onClick="onClick"/>
</LinearLayout>
home.xml
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/create_your_event"
android:id="#+id/toEventButton"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:onClick="onClick"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/manage_your_event"
android:id="#+id/manage_your_guestButton2"
android:layout_gravity="center_horizontal" android:clickable="true"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/your_events"
android:id="#+id/your_eventsButton3"
android:layout_gravity="center_horizontal" android:clickable="true"/>
</LinearLayout>
try this
mainactivity.java
public class MainActivity extends Activity {
Button login;
Button sign_up;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login=(Button)findViewById(R.id.button1);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,HomeActivity.class);
startActivity(i);
}
});
sign_up=(Button)findViewById(R.id.button2);
sign_up.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,HomeActivity.class);
startActivity(i);
}
});
}
}
homeactivity.java
public class HomeActivity extends Activity{
Button button2;
Button button3;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0) {
Intent i = new Intent(HomeActivity.this,EventActivity.class);
HomeActivity.this.
startActivity(i);
}
});
button3=(Button)findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(HomeActivity.this,GuestActivity.class);
HomeActivity.this.
startActivity(i);
}
});
}
}
manifest.xml
define all this class in mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.target"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.target.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 android:name="com.example.target.EventActivity" >
</activity>
<activity android:name="com.example.target.GuestActivity" >
</activity>
<activity android:name="com.example.target.HomeActivity" >
</activity>
</application>

Categories