Image caption RIM's Blackberry has struggled to keep up with other smartphones in the market

Research In Motion has posted a smaller-than-expected quarterly loss, sending its shares up nearly 18% in after-hours trading.

The maker of the Blackberry also boosted its cash pile, as it nears the launch of its next-generation devices.

RIM reported a net loss of $235m (£145m) for the second quarter, ending 1 September, compared with a profit of $329m for the period last year.

Excluding one-time restructuring items, the loss was $142m.

RIM increased its cash to about $2.3bn from $2.2bn.

Being able to dip into a cash reserve could be key to a successful launch of RIM's line of revamped smartphones that will run on its new Blackberry 10, or BB10, operating system.

The struggling company has staked its future on BB10.

Once a smartphone pioneer, RIM's fortunes have faded as rivals such as Apple and Samsung have taken market share.

Thorsten Heins, chief executive of the Ontario-based firm, said: "Despite the significant changes we are implementing across the organization, our second quarter results demonstrate that RIM is progressing on its financial and operational commitments during this major transition."

Technology analyst Rob Enderle, of the Enderle Group, told the BBC: "RIM's turnaround will have to wait until the new platform comes out.

"Its strength is the business-centric audience - and what's hurting them most is they still don't have Blackberry 10 to offer them.

"But given the business market is not that happy with Android over security, and Apple's prevalance means it is also becoming a target - there is still a reasonable chance RIM can still come back.

"Of course, Microsoft is targeting the same audience with Windows Phone 8, but there is an opportunity for a challenger in 2013."

RIM said it shipped 7.4 million Blackberry smartphones in the quarter and 130,000 BlackBerry PlayBook tablets.