What i'm trying to do is this:
Make an alarm app, when the alarmmanager activates, switch to a new activity and open the app (The activity where you can stop the alarm)
What happens now with my code is this:
Alarmmanager goes off, it switches to the new activity but the app does not open. You have to open in manually to see the stop alarm screen. How do i do this?
Mainactivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TimePicker klok = findViewById(R.id.timePicker1);
klok.setIs24HourView(true);
final Button getTimeBtn = findViewById(R.id.getTimeBtn);
final TextView showText = findViewById(R.id.showText);
Intent intent = new Intent(this, AlarmActivation.class);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
final AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
getTimeBtn.setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
int uur = klok.getHour();
int minuut = klok.getMinute();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, uur);
cal.set(Calendar.MINUTE, minuut);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Toast.makeText(getApplication().getApplicationContext(), "Alarm gaat om " + uur + ":" + minuut,Toast.LENGTH_LONG).show();
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
showText.setText(Integer.toString(uur) + ':' + Integer.toString(minuut));
}
});
}
}
AlarmActivation.java
public class AlarmActivation extends BroadcastReceiver {
MediaPlayer mp;
#Override
public void onReceive(Context context, Intent intent) {
Log.d("alarmact", "voor de service");
Intent alarmIntent = new Intent(context, MainActivity2.class);
alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(alarmIntent);
}
}
MainActivity2.java
public class MainActivity2 extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wekkerapp">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity2"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmActivation"></receiver>
<service
android:name=".WekkerService"
android:enabled="true"/>
</application>
</manifest>
Hope someone can help me a little with this
How about make BroadcastReceiver in your MainActivity2 ?
like this.
public class MainActivity2 extends AppCompatActivity {
public static final String BROAD_TAG = "braodTag";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(BROAD_TAG));
}
public BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
if (isRunningActivity) {
//get Data from intent if you need
}
}
}
};
}
and when you send Data, (AlarmActivation.java)
public class AlarmActivation extends BroadcastReceiver {
MediaPlayer mp;
#Override
public void onReceive(Context context, Intent intent) {
Log.d("alarmact", "voor de service");
Intent braodintent = new Intent(MainActivity2.BROAD_TAG);
LocalBroadcastManager.getInstance(this).sendBroadcast(braodintent);
}
}
Related
I found this Question multiple times but none of the Solutions seemed to work.
I have the following in the manifest:
<receiver android:name=".noactivity.Airplane">
<intent-filter>
<action android:name="android.intent.action.AIRPLANE_MODE_CHANGED"/>
</intent-filter>
</receiver>
And the following class:
public class Airplane extends BroadcastReceiver {
public Airplane(){
}
#Override
public void onReceive(Context context, Intent intent) {
Log.d("AirplaneMode", "Service state changed");
Toast.makeText(context,"Airplane mode changed",Toast.LENGTH_LONG).show();
}}
But if I change the Airplane mode nothing happens. To be sure I also added:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerReceiver(new Airplane(), new IntentFilter("android.intent.action.AIRPLANE_MODE_CHANGED"));
}}
What also didn't work.
Do any of you know what I'm doing wrong?
I use this successfully without adding the receiver in manifest.
In you activity add this:
#Override
protected void onResume() {
//register receiver for air plane mode states
IntentFilter airPlaneModeFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(airPlaneModeReceiver, airPlaneModeFilter);
super.onResume();
}
private BroadcastReceiver airPlaneModeReceiver = new BroadcastReceiver() {#Override
public void onReceive(Context context, Intent intent) {
boolean airPlaneModeEnabled = intent.getBooleanExtra("state", false);
if (airPlaneModeEnabled) {
} else {
}
}
};
#Override
protected void onPause() {
if (airPlaneModeReceiver != null) unregisterReceiver(airPlaneModeReceiver);
super.onPause();
}
I keep getting this build error 'class' or 'interface' expected. Everything I'm finding on SO is saying that my Java class is missing (or has an extra) a "}" I'm getting this error in my AndroidManifest.xml for all my Java activities. Here is the Java code:
public class MainActivity extends AppCompatActivity {
protected static final String TAG = "com.example.grey";
EditText SendValue;
Button SendEditTextValue;
Intent intent;
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
Log.d(TAG, "onCreate started from Main Activity");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater mMenuInflater = getMenuInflater();
mMenuInflater.inflate(R.menu.my_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.action_setting){
Toast.makeText(MainActivity.this,
"Settings Clicked",
Toast.LENGTH_SHORT).show();
}
if(item.getItemId() == R.id.about_us){
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
public void sendButton(View view){
SendEditTextValue = (Button) findViewById(R.id.button1);
SendValue = (EditText) findViewById(R.id.editText1);
SendEditTextValue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
intent = new Intent(getApplicationContext(), TextBoxMsgSend.class);
intent.putExtra("EdiTtEXTvALUE", SendValue.getText().toString());
startActivity(intent);
}
});
}
public void movieButton(View view){
Intent intent = new Intent(this, ShowMovies.class);
startActivity(intent);
}
public void button7(View view){
CharSequence text = "Two";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.show();
}
public void button8(View view){
CharSequence text = "Three";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.show();
}
public void button9(View view){
CharSequence text = "Four";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.show();
}
#Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart started from Main Activity");
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause started from Main Activity");
}
#Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop started from Main Activity");
}
#Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy started from Main Activity");
}
#Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart started from Main Activity");
}
}
And here is the AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.grey">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<!-- The main/home activity (it has no parent activity) -->
<activity android:name="MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- A child of the main activity -->
<activity
android:name=".TextBoxMsgSend"
android:parentActivityName=".MainActivity" />
<activity
android:name=".ShowMovies"
android:parentActivityName=".MainActivity" />
<activity
android:name=".RecyclerAdapter"
android:parentActivityName=".MainActivity" />
<activity
android:name=".MovieDetails"
android:parentActivityName=".ShowMovies" />
<activity
android:name=".AboutActivity"
android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.grey.MainActivity" />
</activity>
</application>
</manifest>
I keep getting build errors and am not able to do any commits. It was working fine the other day so I'm not really sure what changed. I can post my other activities if needed.
public class MovieDetails extends AppCompatActivity{
private static final String TAG = "MovieDetailsActivity";
#Override
protected void onCreate(#Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_details);
Log.d(TAG, "Started program.");
getGalleryIntent();
}
private void getGalleryIntent(){
if(getIntent().hasExtra("image_url") && getIntent().hasExtra("image_name")){
Log.d(TAG,"Found intents.");
String imageURL = getIntent().getStringExtra("image_url");
String imageName = getIntent().getStringExtra("image_name");
String imageYear = getIntent().getStringExtra("image_year");
String imageDirector = getIntent().getStringExtra("image_director");
String imageDescription = getIntent().getStringExtra("image_description");
setImage(imageURL, imageName, imageYear, imageDirector, imageDescription);
}
}
private void setImage(String imageURL, String imageName, String imageYear, String imageDirector, String imageDescription){
TextView name = findViewById(R.id.title);
name.setText(imageName);
TextView year = findViewById(R.id.year);
year.setText(imageYear);
TextView director = findViewById(R.id.director);
director.setText(imageDirector);
TextView description = findViewById(R.id.description);
description.setText(imageDescription);
ImageView image = findViewById(R.id.image);
Glide.with(this).asBitmap().load(imageURL).into(image);
}
}
Try a period before MainActivity where it's declared in the manifest.
I'm beginner in Android Studio. My app allows me to add users(fn,ln,adrs,Uri::ImageUri) and list them and view their info.
I want to be able to display one user's info when clicking on my listview.
The problem is that i only get a blank space instead of my desired imageview.
My main activity :
public class MainActivity extends AppCompatActivity {
public static ArrayList <User> users =new ArrayList <User>();
public static User userSelected;
public static ListView mListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_main);
mListView = (ListView) findViewById(R.id.List);
}
public void InputInfo(View view) {
Intent AddEmployee = new Intent(this, NewEmployeeInfo.class);
startActivityForResult(AddEmployee,0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(0, resultCode, data);
finaltest =NewEmployeeInfo .targetUri ;
UserAdapter useradapter;
useradapter = new UserAdapter (MainActivity .this, android.R.layout.simple_list_item_1, users ) ;
mListView.setAdapter(useradapter );
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
Intent appInfo = new Intent(MainActivity.this, DisplayInfo.class);
User temp= users.get(position );
userSelected =new User(temp.first_name ,temp.last_name,temp.adr,temp.url );
startActivity(appInfo);
}
});
}
}
My second one (where the user inputs the info :
public class NewEmployeeInfo extends AppCompatActivity {
public ImageView imageview;
public ImageView targetImage;
public User u;
public static Bitmap photo;
public static Uri targetUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_employee_info);
}
public void takePhoto(View view) {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);
}
public void pickphoto(View view) {
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto, 1);
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
imageview = (ImageView) this.findViewById(imageView);
resultphoto(requestCode, resultCode, imageReturnedIntent);
}
public void Save(View view) {
Intent SaveDataIntent = new Intent(this, MainActivity.class);
EditText FN = (EditText) findViewById(R.id.editText);
EditText LN = (EditText) findViewById(R.id.editText5);
EditText ADDRESS = (EditText) findViewById(R.id.editText6);
String firstname = FN.getText().toString();
String lastname = LN.getText().toString();
String address = ADDRESS.getText().toString();
if (firstname.length() == 0 || lastname.length() == 0 || address.length() == 0) {
Toast.makeText(this, "No Emty Fields!!",
Toast.LENGTH_LONG).show();
return;
}
u = new User(firstname, lastname, address, targetUri);
users.add(u);
setResult(RESULT_OK, SaveDataIntent);
finish();
}
private void resultphoto(int requestCode, int resultCode, Intent imageReturnedIntent) {
switch (requestCode) {
case 0:
if (resultCode == RESULT_OK) {
targetUri = imageReturnedIntent.getData();
imageview.setImageURI(targetUri);
imageReturnedIntent.getExtras().get("data");
}
break;
case 1:
if (resultCode == RESULT_OK) {
targetUri = imageReturnedIntent.getData();
targetImage = (ImageView) findViewById(imageView);
try {
photo = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
targetImage.setImageBitmap(photo);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
break;
}
}
}
the third and final one(Where the info should be displayed)
public class DisplayInfo extends AppCompatActivity {
public ImageView imageView;
public Bitmap image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_info);
TextView fn = (TextView) findViewById(R.id.firstname);
TextView ln = (TextView) findViewById(R.id.lastname);
TextView adr = (TextView) findViewById(R.id.address);
imageView = (ImageView) findViewById(R.id.imageView2);
fn.setText(MainActivity.userSelected.first_name);
ln.setText(MainActivity.userSelected.last_name);
adr.setText(MainActivity.userSelected.adr);
imageView.setImageURI(MainActivity.userSelected.url ) ;
This error keep showing up
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/810 from pid=12644, uid=10280 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
Though I included these permissions in my manifest file:
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Ask runTime permissions
tutorial
My problem was in the Manifest file;
It was
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity 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=".NewEmployeeInfo">
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".DisplayInfo" />
<activity android:name=".UserAdapterActivity"></activity>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</application>
I misplaced my permissions. It should've been like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobilonia.employeesapp">
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity 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=".NewEmployeeInfo">
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".DisplayInfo" />
<activity android:name=".UserAdapterActivity"></activity>
</application>
</manifest>
I'm doing a basic activity of moving from one page to another. Everything was going perfect until I get two pages deep into the app. I used the same exact code for each page class, put the activities in the manifest and made sure all words were spelled correctly, etc., but the intent doesn't do anything when I try to go three pages deep. There are no error messages in the log at all. When I click on a button on the third page, it just turns blue but doesn't move to the next page like the previous pages. Here's my code:
from page 1 to 3:
Page1:
public class MainActivity extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton(); }
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, MainMenu.class);
startActivity(intent);
}
});
}
}
Page 2: has more buttons...
public class MainMenu extends ActionBarActivity {
Button button;
Button button2;
Button button3;
Button button4;
Button button5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, OneMain.class);
startActivity(intent);
}
});
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, TwoMain.class);
startActivity(intent);
}
});
button3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, ThreeMain.class);
startActivity(intent);
}
});
button4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, FourMain.class);
startActivity(intent);
}
});
button5.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, FiveMain.class);
startActivity(intent);
}
});
}
}
Page 3:
public class OneMain extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.one_main);
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Alphabet.class);
startActivity(intent);
}
});
}
}
I also made sure I put in all the imports. Someone help. I'm stuck :(.
Here is the manifest xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.juwar74.alarabic"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
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"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".MainMenu" >
</activity>
<activity
android:label="#string/app_name"
android:name=".OneMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".TwoMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".ThreeMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".FourMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".FiveMain" >
</activity>
<activity
android:label="#string/app_name"
android:name=".OneVoc" >
</activity>
</application>
</manifest>
And here is the code for the Alphabet.class
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class Alphabet extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alphabet);
}
}
in page3 you never called addListenerOnButton() .
public class OneMain extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.one_main);
// HERE you missed addListenerOnButton();
}
<activity
android:name=".Alphabet " >
</activity>
You missed this in the manifest.xml
First call addListenerOnButton() in OneMain.java after setContentView.
Then check manifest.
Alphabet.class is not registered in manifest.
<activity
android:label="#string/app_name"
android:name=".Alphabet" >
</activity>
After adding it, make sure you are rendering correct xml in Alphabet.java
I am trying to put 2 different layouts in my android application
and that on value in register using shared preferences
this is my code .. it stopped once i click logo
Part of
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs;
//String register;
prefs = PreferenceManager.getDefaultSharedPreferences(this);
register=prefs.getString("register", "no");
if(register.equalsIgnoreCase("no")) {
setContentView(R.layout.main_activity);
}
else
{
setContentView(R.layout.about);
}
}
the LogCat error
FATAL EXCEPTION: main
Process:com,cpcs,irissystem, PID:31749
java.lang.RuntimeExeption : unable to start activity componentInfo
{......MainActivity }:java.lang.NullPointerException
at android.app.ActivityThread.preformLaunchActivity(ActivityThread.java2328)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java2386)
At android.app.ActivityThread.access$900(ActivityThread.java:169)
At android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
At android.os.Handler.dispatchMeesage(Handler.java:102)
At android.os.looper.loop(LooperLjava:136)
At android.app.ActivityThread.Main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$methodAndArgsCaller.run....:1268)
Activity Class
public class MainActivity extends Activity {
public static String register;
private static final int CAMERA_REQUEST = 1888;
public static String IrisCode;
String IrisCode2;
ImageView imageView;
private static Bitmap eyeImage;
EditText passwordText;
public static float perc ;
SharedPreferences prefs;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
register=prefs.getString("register", "no");
if(register.equalsIgnoreCase("no")) {
setContentView(R.layout.main_activity);
}
else
{
setContentView(R.layout.about);
}
Toast.makeText(MainActivity.this,"befroe: "+ register, Toast.LENGTH_LONG).show();
Button InstructionButton = (Button) findViewById(R.id.inst);
Button enrollButton = (Button) findViewById(R.id.enroll);
Button verifyButton = (Button) findViewById(R.id.ver);
passwordText = (EditText) findViewById(R.id.pass);
if(register.equalsIgnoreCase("no")){
verifyButton.setEnabled(false);
}
enrollButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
//Go to the next page
//if Not registered before go to start to enter data
//else go to setting
Intent i = new Intent();
if(register.equalsIgnoreCase("no")) {
i = new Intent (MainActivity.this,start.class);
startActivity(i);
}
else
{
i = new Intent (MainActivity.this,setting.class);
startActivity(i);
}
}
});
InstructionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
//Go to the instruction page
Intent i = new Intent (MainActivity.this,instruction.class);
startActivity(i);
}
});
verifyButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if("0000".equals(passwordText.getText().toString())){
String same="aothorizes acess";
Toast.makeText(MainActivity.this, same, Toast.LENGTH_LONG).show();
Intent i = new Intent (MainActivity.this,setting.class);
startActivity(i);
}
}
});
}
Manifest
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.cpcs.irissystem.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=".start" />
<activity
android:name=".setting" />
<activity
android:name=".aboutus" />
<activity
android:name=".instruction" />
<activity
android:name=".setting2"/>
<activity
android:name=".ver"/>
</application>
// Try this way,hope this will help you...
SharedPreferences prefs;
String register;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
register=prefs.getString("register", "no");
if(register.equalsIgnoreCase("no")) {
setContentView(R.layout.activity_main);
}
else
{
setContentView(R.layout.activity_main2);
}
}