Android: Passing data to an Activity

In my recent Android project there was a requirement to pass data to other Activity.
You can start the activity using following code:

Intent i = new Intent(context, OtherActivity.class);
context.startActivity(i);

To pass around the data to other activity we can use putExtra() method of Intent class:

Intent i = new Intent(context, OtherActivity.class);
i.putExtra("key1", "value1");
i.putExtra("key2", "value2");
context.startActivity(i);

In the OtherActivity.class get the data using getIntent() method:

String value1 = getIntent().getExtras().getString("key1");
String value2 = getIntent().getExtras().getString("key2");

Converting HTML to Pdf with Java and Qt

Yesterday I wrote about Converting HTML to Pdf with Python and Qt. But in PyQT loadFinished() signal was not working when using setHtml(). Tried with QtJambi today and it works on Windows as well.

Here is the code:

import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.*;
import com.trolltech.qt.webkit.*;

class html2pdf extends QWebView
{
	private QPrinter printer = new QPrinter();

	public html2pdf()
	{
		loadFinished.connect(this, "loadDone()");
		setHtml("This is <b>HTML</b>");
	}

	public void loadDone()
	{
		printer.setPageSize(QPrinter.PageSize.A4);
		printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat);
		printer.setOutputFileName("test.pdf");
		print(printer);
		System.out.println("Done");
		QApplication.exit();
	}

	public static void main(String args[])
	{
		QApplication.initialize(args);

		html2pdf h2p = new html2pdf();
		h2p.show();

		QApplication.exec();
	}
}

Sun begins Close Sourcing MySQL

Old news, but I felt I should write something about it.

First they start with Open Sourcing Java and Solaris calling it OpenJDK and OpenSolaris.

Then they say “It’s just a fucking kernel” because Linus Torvalds didnt release Linux in GPL 3 license.

And now they started to close MySQL features.

But hey guys no need to worry. IT’S JUST A FUCKING DBMS we can use PostgreSQL