• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Big Chungus

Member
Not that I would be of any help but what exactly is the problem?

Trying to get a notification to appear once it hits a certain time, but nothing appears.

Code:
	public void setAlarm()
	{
		AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
		
		Intent i = new Intent(MainActivity.this,MyAlarmReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0,i,PendingIntent.FLAG_ONE_SHOT);
		
		Calendar alarmTime = Calendar.getInstance();
		alarmTime.set(Calendar.HOUR_OF_DAY,8);
		alarmTime.set(Calendar.MINUTE,00);
		
		mgr.set(AlarmManager.RTC_WAKEUP,alarmTime.getTimeInMillis(),pendingIntent);
		
	}

setAlarm gets called when the program starts, and the intent calls MyAlarmReceiver, which just shows a notification on the screen.
 

pompidu

Member
Trying to get a notification to appear once it hits a certain time, but nothing appears.

Code:
	public void setAlarm()
	{
		AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
		
		Intent i = new Intent(MainActivity.this,MyAlarmReceiver.class);
		PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0,i,PendingIntent.FLAG_ONE_SHOT);
		
		[B]Calendar alarmTime = Calendar.getInstance();
		alarmTime.set(Calendar.HOUR_OF_DAY,8);
		alarmTime.set(Calendar.MINUTE,00);[/B]
		
		mgr.set(AlarmManager.RTC_WAKEUP,alarmTime.getTimeInMillis(),pendingIntent);
		
	}

setAlarm gets called when the program starts, and the intent calls MyAlarmReceiver, which just shows a notification on the screen.

Just looked at the api for AlarmManager and a few examples and I don't see really anything wrong with it. It doesn't pop up at all? No errors?
Edit: Is the bolded current time?
 

Big Chungus

Member
Can you possibly post MyAlarmReciever.class? Maybe a problem there with notifications.

Code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MyAlarmReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent i) {

		Toast.makeText(context, "Alarm has sounded!!!", Toast.LENGTH_SHORT).show();
	}

}
 

pompidu

Member
Code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MyAlarmReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, [B]Intent i[/B]) {

		Toast.makeText(context, "Alarm has sounded!!!", Toast.LENGTH_SHORT).show();
	}

}

You can remove that intent since I don't see it being used. Everything looks ok from the API and the examples i've looked at.

Also do something like this in your code so changes can be made, taken straigt from the api
Code:
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();

Edit: Also notice you didn't actually create a Toast object. The example right above me does.
 

pompidu

Member
Still doesn't work, i'm not sure what's going on...maybe it has something to do with the emulator or the time i'm hardcoding in the setAlarm method.
in the set alarm get ride of the calendar and hard coding. Is this like a giant notification in the middle of the screen or in the pull down shade?
 

Big Chungus

Member
in the set alarm get ride of the calendar and hard coding. Is this like a giant notification in the middle of the screen or in the pull down shade?

It appears in the middle of the screen, its not that big.

Got rid of the calendar and the hard coding, nothings changed.
 

pompidu

Member
It appears in the middle of the screen, its not that big.
i havent worked with android but make sure your not using depreciated code that is used for older versions of android than the one your target build is. try to instsll the app on your phone instead of emulator. all the code seems ok. if it still doesnt work, might have to hit up stackoverflow or an android developer forum.

make your myalarm or whatever class a service inside your android manifest xml.
http://android-er.blogspot.com/2010/10/simple-example-of-alarm-service-using.html?m=1
 

squidyj

Member
you can't remove the intent from the onReceive method as that would alter its signature and it wouldn't override the original onReceive in BroadcastReceiver, as such it wouldn't get called when you want it.

Second of all instead of using a static time from a calender for when the alarm should ring, try the current time + 2s
 

Big Chungus

Member
Well, I found the problem, I was supposed to add a simple line to the AndroidManifest.xml file.

There goes 5 hours of me being dumb.

Thanks for the help guys.
 

Hari Seldon

Member
Well, work is giving me the opportunity to go down the rabbit hole of Linux drivers and CUDA programming. Should be great for the resume!
 

iapetus

Scary Euro Man
You can remove that intent since I don't see it being used. Everything looks ok from the API and the examples i've looked at.

Also do something like this in your code so changes can be made, taken straigt from the api
Code:
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();

Edit: Also notice you didn't actually create a Toast object. The example right above me does.

This is all terrible advice. :)

Removing the intent would stop the app compiling, as it wouldn't be overriding the onReceive method correctly.

There's nothing about the suggested refactoring that would make it easier to 'make changes'.

He does actually create a Toast object. That's what Toast.makeText() does. He doesn't assign it to a local variable because he doesn't need to reference it in future.
 
I feel really dumb, but in Java is there a way to cache a string? So basically I do this heavy create-string-from-file routine and I want to keep that string around instead of constantly reloading the file. Any way to throw the string in a cache and check to see if it's there next time I need it instead of reloading it from the file on disk?
 
I feel really dumb, but in Java is there a way to cache a string? So basically I do this heavy create-string-from-file routine and I want to keep that string around instead of constantly reloading the file. Any way to throw the string in a cache and check to see if it's there next time I need it instead of reloading it from the file on disk?

Need more explanation of exactly what you're doing. Do you mean keeping it for 1 run of the program? Then surely just a variable holding the value is all you need. Do you mean between runs of the program?
 
Need more explanation of exactly what you're doing. Do you mean keeping it for 1 run of the program? Then surely just a variable holding the value is all you need. Do you mean between runs of the program?

It's an always-on sort of program, like a server. So yeah, just one run. But I don't know how many of these files I will be reading into strings. It's just a method that reads a filename into a string and does something with it. I might have ten thousand files or just a dozen.
 
You probably want to store them in a map then, how do you refer to the files? Is it all files in a directory? Id number? file name?

As long as you have a unique id for each file you can just store the string in a map, and only call the function that generates the string if that value doesn't exist.

Something like this (reading files from a directory called "data" and storing them based on filename, key has to be unique):

Code:
import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Application {
    static Map<String, String> stringMap = new HashMap<String, String>();
	
    public static void main(String[] args) {
        String[] files = new File("data").list();

	for (String fileName : files) {
	        
	    //check if filename is in map
	    if (stringMap.containsKey(fileName)) {
                String string = stringMap.get(fileName);
                 // do something with string
       } else { 
	            String string = loadFromFile(fileName);
	            // put it in map so next time you look for it it's there
	            stringMap.put(fileName, string);
	            // do something with string
	        }
	    }
	}
    
    public static String loadFromFile(String fileName) {
        String string = "";
        // load your string from file
        return string;
    }
}
 

pompidu

Member
This is all terrible advice. :)

Removing the intent would stop the app compiling, as it wouldn't be overriding the onReceive method correctly.

There's nothing about the suggested refactoring that would make it easier to 'make changes'.

He does actually create a Toast object. That's what Toast.makeText() does. He doesn't assign it to a local variable because he doesn't need to reference it in future.

And like I said I knew nothing about android development and half of the stuff ive shown him is straight from google androids website. So idk lol.
 

squidyj

Member
And like I said I knew nothing about android development and half of the stuff ive shown him is straight from google androids website. So idk lol.

There isn't any part of that that's unique to android development, it's all Java (and even broader than that).
 

pompidu

Member
There isn't any part of that that's unique to android development, it's all Java (and even broader than that).

Intent and Toast are android. And like I said I don't know android well enough to help him or how it actually works. I was just providing examples from various sources. Whether I was right or wrong doesn't really matter since I stated I didn't know it well enough.
Also not a programmer nither.
 

Hellix

Member
Well, I found the problem, I was supposed to add a simple line to the AndroidManifest.xml file.

There goes 5 hours of me being dumb.

Thanks for the help guys.

I been looking into Android development too. From what I understand, every activity needs to be declared in the Manifest file, and I guess that alarm notification is an activity.
 

survivor

Banned
I'm having some trouble with SMTP and Telnet. I need to send an email by using telnet and connecting to the mail server. So generally I have to do this:

telnet server.name 25

and then I get the following results

220 mxbridge ESMTP spamd IP-based SPAM blocker; Tue May 21 22:19:15 2013

So I'm assuming something is acting up cause even if I continue and add stuff to helo, mail from, rctp to, I keep getting warning messages about spam. So is this a problem on my end with something wrong with my settings/I'm doing something stupid or is it a problem with the server? Cause I'm connecting to one provided by the school so I don't know if I can modify anything about it.
 

SapientWolf

Trucker Sexologist
I'm having some trouble with SMTP and Telnet. I need to send an email by using telnet and connecting to the mail server. So generally I have to do this:

telnet server.name 25

and then I get the following results

220 mxbridge ESMTP spamd IP-based SPAM blocker; Tue May 21 22:19:15 2013

So I'm assuming something is acting up cause even if I continue and add stuff to helo, mail from, rctp to, I keep getting warning messages about spam. So is this a problem on my end with something wrong with my settings/I'm doing something stupid or is it a problem with the server? Cause I'm connecting to one provided by the school so I don't know if I can modify anything about it.
How does the server handle authentication?
 

SapientWolf

Trucker Sexologist
I'm not seeing anything in the lab question instructions that talks about authentication. Is there a way for me to find out manually how it handles authentication?

The greylisting technique returns a 451 error code to any mail sender that spamd doesn't yet know about, and will continue to return that error code to that same sender for a configurable time (25 minutes by default) based on three fields:

the sender's IP address,
the From: field in the email header, and
the To: field in the email header.

This trio, called a tuple, gets put in quarantine, so if the sender does retry before the 25-minute quarantine is over, it will continue to get the 451 error. At the expiration of the quarantine, that sender gets put on a temporary "whitelist" lasting for several hours (four hours by default, including the original 25 minutes). Well-behaved MTAs that try again will be successful, and spamd will pass the email through to your real MTA.
http://archive09.linux.com/articles/61103

http://www.openbsd.org/cgi-bin/man.cgi?query=spamd

Might need to wait 25 min.
 

gnrmjd

Member
What exactly is a "working sample"?

I've been applying to internships (I'm a junior in college....about to be a senior.) and one of them wants "working samples."

I don't really understand what this means. Is it an example of code or something?

I don't really know what to send. I mean I have my projects from school, like my game design project which was huge, but most of what I've done has been a group project. I don't think I've had a solo project where I didn't have a group since my sophmore year first semester, so I don't really know what to show.

I don't really even know what they're looking for with this....
 
What exactly is a "working sample"?

I've been applying to internships (I'm a junior in college....about to be a senior.) and one of them wants "working samples."

I don't really understand what this means. Is it an example of code or something?

I don't really know what to send. I mean I have my projects from school, like my game design project which was huge, but most of what I've done has been a group project. I don't think I've had a solo project where I didn't have a group since my sophmore year first semester, so I don't really know what to show.

I don't really even know what they're looking for with this....

I'd say it doesn't have to be your solo effort, just put it to the cover letter thing:

Code:
Name: Some project
    - Coded some more GDDR5 RAM to the metal and made the dancing baby.gif AI in PHP
 

nan0

Member
What exactly is a "working sample"?

I've been applying to internships (I'm a junior in college....about to be a senior.) and one of them wants "working samples."

I don't really understand what this means. Is it an example of code or something?

I don't really know what to send. I mean I have my projects from school, like my game design project which was huge, but most of what I've done has been a group project. I don't think I've had a solo project where I didn't have a group since my sophmore year first semester, so I don't really know what to show.

I don't really even know what they're looking for with this....

Then send them one or two of the more impressive group efforts, and point out the parts you coded/were responsible for. Depending on how demonstratable the stuff is (just a single exe with some libraries? Some Web service that would require deployment?), send them either a running sample plus your code (eh, may be a bad idea to send executable stuff with your application), or only your code. I don't think they will want to sift through a big ass project with some thousand lines of code. They probably want to check if you actually can code, and how your coding style is. Be sure to know about the things you've coded, they may ask some questions about it in an interview. And have that stuff ready on a USB stick in case they want to see more.
 

gnrmjd

Member
Shoot, I don't really know what to do. I mean my only experience is on school projects.

I had a very extensive game design course this semester, but I was the least experienced coder on my team. The project is huuuuuge, but is the most impressive thing I've worked on. I could bring it but I'd have to show them exactly where my code precisely is I guess....? The thing is most of the really hard stuff was done by some of my more experienced group members.

And otherwise my other projects really aren't very visual besides that game. I don't really have much else to show off.....I don't know what to bring or show or what kind of project they're looking for. For example I took a class, Natural Language Processing, this semester....we had to do projects like a project that inputs a document in a certain format and does analysis to train a language model, and then uses those language models to predict aspects about a test file (such as author, etc...) that's not really an easy thing to show without a ton of explanation of what it's doing and it's a ton of code as well.....

I don't really have anything succinct....the semester before that we coded in OCaml which they probably can't even read since most people don't know what it is...and if I go back further Im going back to projects where a lot of the framework was provided by the assignments themselves.
 

dgenx

Made an agreement with another GAF member, refused to honor it because he was broke, but then had no problem continuing to buy video games.
Hello ,

I'm trying to so an iPhone app, the app shows you in a table categories you tap on one and it list you a lot of times , all of them fetched from a database , then if the user want it can save some of the showed data to make a list , like a supermarket list.

What I want to know is any guidance to Tamar This work , what to use SQLite , core data, view Table or table view controller , any good tutorial etc.

Thanks
 

V_Arnold

Member
anyone else do html5 game development? wondering if theres anyone else on gaf

Yes! In the past two months, I kept rebuilding my engine from scratch (only using canvas and Jquery for standardized mouse/keyboard inputs, but before that, I actually built an input system that worked on all four systems.... but it was a pain in the ass), first it was only some stuff to draw pictures on, then I got into units, then scenes holding units, then switching between scenes, then animations and actions, then interactivity... and here I am, working on the newest version that works with five canvases and tries to be as efficient with redraws as possible :D

The biggest hurdles are coming now, as I am just realizing that I will need to touch java+openGl ES sooner or later because my Xperia Mini cant handle the optimized html5 code for more than 22 fps...which is sad. Maybe I should not use the default browser, I dunno. (The game is fully 2d, nothing 3d or fancy about it). (Desktop PC's are the first target for the game anyway, but mobile ports are inevitable at this point.)

If you have any questions to ask or experiences to share, please do so! It is sometimes boring not being able to talk with anyone about specific stuff that I am currently doing -.-
 

Everdred

Member
For PHP:
So i think I just found out that $_SESSION and normal variables equal the same thing? Is this the case?

$user_id is the same as $_SESSION["user_id"]?

I've been using the 2 separately at the same time but they are overwriting each other.
 

wolfmat

Confirmed Asshole
anyone else do html5 game development? wondering if theres anyone else on gaf

Yeah, I'm doing things. Also WebGL. Mostly prototyping and fiddling around to figure out where the issues are. The sound situation is not up to snuff, for example. Gotta code sensible buffering on your own. Keydown keypress keyup is still broken in JS as well; varies from browser to browser and OS to OS. Also, hack ~> adapt to platform has some serious hurdles as well, which I didn't expect, but that's mostly under-the-hood stuff, like writing well-behaved timers.
 

hateradio

The Most Dangerous Yes Man

A Human Becoming

More than a Member
This is a long shot because it doesn't use normal Python (and it's based on 2, not 3), but I'm hoping someone here can help me with my project. I'm very stuck on what to do next.

http://www.codeskulptor.org/#user14_QQ3afOeAMD_15.py

This is the main obstacle right now:

Code:
exposed = [False] * 16

def mouseclick(pos):
    global g, exposed
    g = (pos[0] - 1) / 50
    exposed[int(g)] = True

def draw(canvas):
    image_x = range(25, 800, 50)
    image_n = range(12, 800, 50)

for v in range(len(exposed)):
        if exposed[v] == False:
            for v in image_x:
                canvas.draw_image(image, source_center, image_size, (v, 50), (50, 100))
        elif exposed[v] == True:
            for v in range(len(choices)):
                canvas.draw_text(str(choices[v]), (image_n[v], 66), 50, "White")
I want the image to disappear and the number to show when I click a spot. I can't move onto the next step until I can do this.
 

Big Chungus

Member
Not sure why my program is doing this but whenever this method is called:

Code:
	public void createFile(View v)
	{
		File file = new File("mnt/sdcard/player.txt");
		BufferedWriter bw = null;
		FileWriter fw;
		
		EditText name = (EditText) findViewById(R.id.editText1);
		
		Toast.makeText(this, "This works", Toast.LENGTH_SHORT).show();
		try 
		{
			file.createNewFile();
			
			fw = new FileWriter(file);
			
			bw = new BufferedWriter(fw);
			

			bw.write("Bob");
			
			bw.newLine();

			bw.write("is");
			
			bw.newLine();

			bw.write("cool");
			
		} 
		catch (FileNotFoundException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		finally
		{
			try
			{
				if(bw != null)
				{
					bw.close();
				}
			}
			catch(IOException ex)
			{
				ex.printStackTrace();
			}	
		}

		loadMainScreen();		
	}

It gets saved in a txt file as "Bobiscool"

Instead of displaying each of the words on a new line.

btw, this is in Android, the method gets called when the user clicks on a button.
 
Ugh.

So, I run a LAN subversion server at home (single user == me) for file sync across devices, and ... somehow it got a tree conflict.

With me doing successive commits on one machine. WTF, subversion? Go home, you're drunk.
 
Top Bottom