RadioShack Corp.'s (RSH) second-quarter profit rose 18% amid a year-earlier charge as earnings topped expectations while the consumer-electronics retailer dealt with falling margins.

The company has been seeking a way to stay relevant as companies such as Best Buy Co. (BBY) and Wal-Mart Stores Inc. (WMT) take increasing market share in the consumer-electronics space. RadioShack is renovating most company-owned stores and taking steps such as having an electronics trade-in program in those locations.

It posted income of $48.8 million, or 39 cents a share, up from $41.4 million, or 32 cents a share, a year earlier. The prior year's results included a $4.3 million charge related to the amendment of its headquarters lease, which was partly offset by a state sales-tax settlement.

Revenue decreased 2.9% to $965.7 million as same-store sales fell 4%. Online sales rose 24%.

Analysts polled by Thomson Reuters expected earnings of 28 cents and revenue of $977 million.

Gross margin fell to 46.1% from 47.2%, hurt by a change in sales mix toward lower-margin products such as digital televisions and netbooks.

Earlier this month, the company said it will offer in its stores products and services from Deutsche Telekom AG's (DT) T-Mobile cellphone unit, giving it another way to lure cellphone customers.

Cash levels rose 61% while inventories dropped 7.7%.

RadioShack's shares closed Friday at $16.06 and haven't traded premarket. The stock is up 35% this year.

-By Kerry Grace Benn, Dow Jones Newswires; 212-416-2353; kerry.benn@dowjones.com